From fe9ba8abf323bedbea9eb1fa5b17c0093e7b11ce Mon Sep 17 00:00:00 2001 From: Sebastian Blank Date: Tue, 16 Dec 2014 10:38:12 +0100 Subject: [PATCH] Fix EZP-23518: Clearing image aliases with Symfony console with --purge option results in PHP warnings --- .../Resources/config/fieldtype_services.yml | 1 - .../Core/FieldType/Image/ImageStorage.php | 4 +- .../Core/MVC/Legacy/Image/AliasCleaner.php | 12 +---- .../Legacy/Tests/Image/AliasCleanerTest.php | 54 +++++++++++++++++++ 4 files changed, 56 insertions(+), 15 deletions(-) create mode 100644 eZ/Publish/Core/MVC/Legacy/Tests/Image/AliasCleanerTest.php diff --git a/eZ/Bundle/EzPublishLegacyBundle/Resources/config/fieldtype_services.yml b/eZ/Bundle/EzPublishLegacyBundle/Resources/config/fieldtype_services.yml index 0610cb22600..2a92db86f0c 100644 --- a/eZ/Bundle/EzPublishLegacyBundle/Resources/config/fieldtype_services.yml +++ b/eZ/Bundle/EzPublishLegacyBundle/Resources/config/fieldtype_services.yml @@ -7,6 +7,5 @@ services: class: %ezpublish_legacy.image_alias.cleaner.class% arguments: - @ezpublish.image_alias.imagine.alias_cleaner - - @ezpublish.fieldType.ezimage.io_service - @ezpublish.core.io.image_fieldtype.legacy_url_redecorator lazy: true diff --git a/eZ/Publish/Core/FieldType/Image/ImageStorage.php b/eZ/Publish/Core/FieldType/Image/ImageStorage.php index 4089fc7d4b3..b59731a960f 100644 --- a/eZ/Publish/Core/FieldType/Image/ImageStorage.php +++ b/eZ/Publish/Core/FieldType/Image/ImageStorage.php @@ -239,9 +239,7 @@ public function deleteFieldData( VersionInfo $versionInfo, array $fieldIds, arra if ( $this->aliasCleaner ) { - $this->aliasCleaner->removeAliases( - $this->IOService->loadBinaryFileByUri( $storedFiles['original'] ) - ); + $this->aliasCleaner->removeAliases( $storedFiles['original'] ); } foreach ( $storedFiles as $storedFilePath ) diff --git a/eZ/Publish/Core/MVC/Legacy/Image/AliasCleaner.php b/eZ/Publish/Core/MVC/Legacy/Image/AliasCleaner.php index df60ddd87b7..48b11209681 100644 --- a/eZ/Publish/Core/MVC/Legacy/Image/AliasCleaner.php +++ b/eZ/Publish/Core/MVC/Legacy/Image/AliasCleaner.php @@ -10,7 +10,6 @@ namespace eZ\Publish\Core\MVC\Legacy\Image; use eZ\Publish\Core\FieldType\Image\AliasCleanerInterface; -use eZ\Publish\Core\IO\IOServiceInterface; use eZ\Publish\Core\IO\UrlRedecoratorInterface; class AliasCleaner implements AliasCleanerInterface @@ -20,11 +19,6 @@ class AliasCleaner implements AliasCleanerInterface */ private $innerAliasCleaner; - /** - * @var IOServiceInterface - */ - private $ioService; - /** * @var UrlRedecoratorInterface */ @@ -32,21 +26,17 @@ class AliasCleaner implements AliasCleanerInterface public function __construct( AliasCleanerInterface $innerAliasCleaner, - IOServiceInterface $ioService, UrlRedecoratorInterface $urlRedecorator ) { $this->innerAliasCleaner = $innerAliasCleaner; - $this->ioService = $ioService; $this->urlRedecorator = $urlRedecorator; } public function removeAliases( $originalPath ) { $this->innerAliasCleaner->removeAliases( - $this->ioService->loadBinaryFileByUri( - $this->urlRedecorator->redecorateFromTarget( $originalPath ) - ) + $this->urlRedecorator->redecorateFromTarget( $originalPath ) ); } } diff --git a/eZ/Publish/Core/MVC/Legacy/Tests/Image/AliasCleanerTest.php b/eZ/Publish/Core/MVC/Legacy/Tests/Image/AliasCleanerTest.php new file mode 100644 index 00000000000..e1f95296829 --- /dev/null +++ b/eZ/Publish/Core/MVC/Legacy/Tests/Image/AliasCleanerTest.php @@ -0,0 +1,54 @@ +innerAliasCleaner = $this->getMock( 'eZ\Publish\Core\FieldType\Image\AliasCleanerInterface' ); + $this->urlRedecorator = $this->getMock( 'eZ\Publish\Core\IO\UrlRedecoratorInterface' ); + $this->aliasCleaner = new AliasCleaner( $this->innerAliasCleaner, $this->urlRedecorator ); + } + + public function testRemoveAliases() + { + $originalPath = 'foo/bar/test.jpg'; + + $this->urlRedecorator + ->expects( $this->once() ) + ->method( 'redecorateFromTarget' ) + ->with( $originalPath ); + + $this->innerAliasCleaner + ->expects( $this->once() ) + ->method( 'removeAliases' ); + + $this->aliasCleaner->removeAliases( $originalPath ); + } +}