Skip to content

Commit

Permalink
Merge branch 'hotfix/v2.1.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
ambroisemaupate committed Apr 4, 2023
2 parents 398ae3c + 8d98e98 commit d265a9c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 10 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [v2.1.7](https://github.com/roadiz/core-bundle-dev-app/compare/v2.1.6...v2.1.7) (2023-04-04)


### Bug Fixes

* **Documents:** Prevent renaming document filename if new pathname is not available ([13982cc](https://github.com/roadiz/core-bundle-dev-app/commit/13982cce13b1876d6f55167a40abcb456cd1e64f))

## [v2.1.6](https://github.com/roadiz/core-bundle-dev-app/compare/v2.1.5...v2.1.6) (2023-03-23)


Expand Down
26 changes: 17 additions & 9 deletions lib/Documents/src/AbstractDocumentFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,25 @@ public function findAudiosWithFilename(string $fileName): iterable
*/
public function findPicturesWithFilename(string $fileName): iterable
{
$basename = pathinfo($fileName);
$basename = $basename['filename'];

$sourcesDocsName = [
$basename . '.jpg',
$basename . '.gif',
$basename . '.png',
$basename . '.jpeg',
$basename . '.webp',
$pathInfo = pathinfo($fileName);
$basename = $pathInfo['filename'];
$currentExtension = $pathInfo['extension'];
$extensionsList = [
'jpg',
'gif',
'png',
'jpeg',
'webp',
'avif',
];

// remove current extension from list
$extensionsList = array_diff($extensionsList, [$currentExtension]);
// list sources paths for extensions
$sourcesDocsName = array_values(array_map(function ($extension) use ($basename) {
return $basename . '.' . $extension;
}, $extensionsList));

return $this->findAllByFilenames($sourcesDocsName);
}
}
3 changes: 3 additions & 0 deletions lib/Documents/src/Events/DocumentLifeCycleSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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 @@ -60,6 +61,8 @@ public function preUpdate(PreUpdateEventArgs $args): void
* 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);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/RoadizCoreBundle/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ services:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
bind:
$cmsVersion: '2.1.6'
$cmsVersion: '2.1.7'
$appVersion: '%roadiz_core.app_version%'
$cmsVersionPrefix: 'main'
$staticDomain: '%roadiz_core.static_domain_name%'
Expand Down
3 changes: 3 additions & 0 deletions lib/Rozier/src/Controllers/Documents/DocumentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use GuzzleHttp\Exception\RequestException;
use League\Flysystem\FilesystemException;
use League\Flysystem\FilesystemOperator;
use League\Flysystem\UnableToMoveFile;
use Psr\Log\LoggerInterface;
use RZ\Roadiz\Core\Handlers\HandlerFactoryInterface;
use RZ\Roadiz\CoreBundle\Document\DocumentFactory;
Expand Down Expand Up @@ -366,6 +367,8 @@ public function editAction(Request $request, int $documentId): Response
'documentsEditPage',
$routeParams
);
} catch (FilesystemException $exception) {
$form->get('filename')->addError(new FormError($exception->getMessage()));
} catch (FileException $exception) {
$form->get('filename')->addError(new FormError($exception->getMessage()));
}
Expand Down

0 comments on commit d265a9c

Please sign in to comment.