Skip to content

Commit

Permalink
Merge pull request ezsystems#1141 from blankse/EZP-23518-fix_alias_cl…
Browse files Browse the repository at this point in the history
…eaner

Fix EZP-23518: Clearing image aliases with Symfony console with --purge ...
  • Loading branch information
yannickroger committed Jan 16, 2015
2 parents 3484808 + fe9ba8a commit b0b79a6
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 15 deletions.
Expand Up @@ -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
4 changes: 1 addition & 3 deletions eZ/Publish/Core/FieldType/Image/ImageStorage.php
Expand Up @@ -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 )
Expand Down
12 changes: 1 addition & 11 deletions eZ/Publish/Core/MVC/Legacy/Image/AliasCleaner.php
Expand Up @@ -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
Expand All @@ -20,33 +19,24 @@ class AliasCleaner implements AliasCleanerInterface
*/
private $innerAliasCleaner;

/**
* @var IOServiceInterface
*/
private $ioService;

/**
* @var UrlRedecoratorInterface
*/
private $urlRedecorator;

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 )
);
}
}
54 changes: 54 additions & 0 deletions eZ/Publish/Core/MVC/Legacy/Tests/Image/AliasCleanerTest.php
@@ -0,0 +1,54 @@
<?php
/**
* File containing the AliasCleanerTest class.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
* @version //autogentag//
*/
namespace eZ\Publish\Core\MVC\Legacy\Tests\Image;

use eZ\Publish\Core\MVC\Legacy\Image\AliasCleaner;
use PHPUnit_Framework_TestCase;

class AliasCleanerTest extends PHPUnit_Framework_TestCase
{
/**
* @var \eZ\Publish\Core\MVC\Legacy\Image\AliasCleaner
*/
private $aliasCleaner;

/**
* @var \eZ\Publish\Core\FieldType\Image\AliasCleanerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $innerAliasCleaner;

/**
* @var \eZ\Publish\Core\IO\UrlRedecoratorInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $urlRedecorator;

protected function setUp()
{
parent::setUp();
$this->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 );
}
}

0 comments on commit b0b79a6

Please sign in to comment.