Skip to content

Commit

Permalink
Merge branch 'hotfix/v2.3.28'
Browse files Browse the repository at this point in the history
  • Loading branch information
ambroisemaupate committed Sep 24, 2024
2 parents 8b06427 + b9f4412 commit cca0152
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to Roadiz will be documented in this file.

## [2.3.28](https://github.com/roadiz/core-bundle-dev-app/compare/v2.3.27...v2.3.28) - 2024-09-24

### Bug Fixes

- **(Documents)** Do not throw `UnableToMoveFile` when document `filename` changes because we update the whole file - ([da5386e](https://github.com/roadiz/core-bundle-dev-app/commit/da5386e0cab580ec1a414f91779c1a1fbcc14160))

## [2.3.27](https://github.com/roadiz/core-bundle-dev-app/compare/v2.3.26...v2.3.27) - 2024-09-13

### Bug Fixes
Expand Down
40 changes: 26 additions & 14 deletions lib/Documents/src/Events/DocumentLifeCycleSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Doctrine\Persistence\Event\LifecycleEventArgs;
use League\Flysystem\FilesystemException;
use League\Flysystem\FilesystemOperator;
use League\Flysystem\UnableToMoveFile;
use League\Flysystem\Visibility;
use RZ\Roadiz\Documents\Exceptions\DocumentWithoutFileException;
use RZ\Roadiz\Documents\Models\DocumentInterface;
Expand Down Expand Up @@ -52,19 +51,9 @@ public function preUpdate(PreUpdateEventArgs $args): void
&& is_string($args->getNewValue('filename'))
&& $args->getOldValue('filename') !== ''
) {
$oldPath = $this->getDocumentMountPathForFilename($document, $args->getOldValue('filename'));
$newPath = $this->getDocumentMountPathForFilename($document, $args->getNewValue('filename'));

if ($oldPath !== $newPath) {
if ($this->documentsStorage->fileExists($oldPath) && !$this->documentsStorage->fileExists($newPath)) {
/*
* Only perform IO rename if old file exists and new path is free.
*/
$this->documentsStorage->move($oldPath, $newPath);
} else {
throw new UnableToMoveFile('Cannot rename file from ' . $oldPath . ' to ' . $newPath);
}
}
// This method must not throw any exception
// because filename WILL change if document file is updated too.
$this->renameDocumentFilename($document, $args);
}
if ($document instanceof DocumentInterface && $args->hasChangedField('private')) {
if ($document->isPrivate() === true) {
Expand All @@ -75,6 +64,29 @@ public function preUpdate(PreUpdateEventArgs $args): void
}
}

private function renameDocumentFilename(DocumentInterface $document, PreUpdateEventArgs $args): void
{
$oldPath = $this->getDocumentMountPathForFilename($document, $args->getOldValue('filename'));
$newPath = $this->getDocumentMountPathForFilename($document, $args->getNewValue('filename'));

if ($oldPath === $newPath) {
return;
}

if (!$this->documentsStorage->fileExists($oldPath)) {
// Do not throw, just return
return;
}
if ($this->documentsStorage->fileExists($newPath)) {
// Do not throw, just return
return;
}
/*
* Only perform IO rename if old file exists and new path is free.
*/
$this->documentsStorage->move($oldPath, $newPath);
}

/**
* @param DocumentInterface $document
* @param PreUpdateEventArgs $args
Expand Down
2 changes: 1 addition & 1 deletion lib/RoadizCoreBundle/config/services.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
parameters:
roadiz_core.cms_version: '2.3.27'
roadiz_core.cms_version: '2.3.28'
roadiz_core.cms_version_prefix: 'main'
env(APP_NAMESPACE): "roadiz"
env(APP_VERSION): "0.1.0"
Expand Down

0 comments on commit cca0152

Please sign in to comment.