-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EZP-28747: HTTP Cache purge when UserService\{CreateUser,CreateUserGr…
…oup,UpdateUser,UpdateUserGroup}Signal is emited. (#50)
- Loading branch information
Showing
14 changed files
with
351 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the eZ Publish Kernel package. | ||
* | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
namespace EzSystems\PlatformHttpCacheBundle\SignalSlot; | ||
|
||
use eZ\Publish\Core\SignalSlot\Signal; | ||
use eZ\Publish\SPI\Persistence\Content\Location\Handler; | ||
use EzSystems\PlatformHttpCacheBundle\PurgeClient\PurgeClientInterface; | ||
|
||
abstract class AbstractPublishSlot extends AbstractContentSlot | ||
{ | ||
/** | ||
* @var \eZ\Publish\SPI\Persistence\Content\Location\Handler | ||
*/ | ||
private $locationHandler; | ||
|
||
/** | ||
* @param \EzSystems\PlatformHttpCacheBundle\PurgeClient\PurgeClientInterface $purgeClient | ||
* @param \eZ\Publish\SPI\Persistence\Content\Location\Handler $spiLocationHandler | ||
*/ | ||
public function __construct(PurgeClientInterface $purgeClient, Handler $spiLocationHandler) | ||
{ | ||
parent::__construct($purgeClient); | ||
$this->locationHandler = $spiLocationHandler; | ||
} | ||
|
||
/** | ||
* Extracts content id from signal. | ||
* | ||
* @param Signal $signal | ||
* @return mixed | ||
*/ | ||
abstract protected function getContentId(Signal $signal); | ||
|
||
protected function generateTags(Signal $signal) | ||
{ | ||
$contentId = $this->getContentId($signal); | ||
|
||
$tags = [ | ||
// self in all forms (also without locations) | ||
'content-' . $contentId, | ||
// reverse relations | ||
'relation-' . $contentId, | ||
]; | ||
|
||
foreach ($this->locationHandler->loadLocationsByContent($contentId) as $location) { | ||
// self | ||
$tags[] = 'location-' . $location->id; | ||
// children | ||
$tags[] = 'parent-' . $location->id; | ||
// parent | ||
$tags[] = 'location-' . $location->parentId; | ||
// siblings | ||
$tags[] = 'parent-' . $location->parentId; | ||
} | ||
|
||
return $tags; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the eZ Publish Kernel package. | ||
* | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
namespace EzSystems\PlatformHttpCacheBundle\SignalSlot; | ||
|
||
use eZ\Publish\Core\SignalSlot\Signal; | ||
|
||
/** | ||
* A slot handling CreateUserGroupSlot. | ||
*/ | ||
class CreateUserGroupSlot extends AbstractPublishSlot | ||
{ | ||
protected function supports(Signal $signal) | ||
{ | ||
return $signal instanceof Signal\UserService\CreateUserGroupSignal; | ||
} | ||
|
||
protected function getContentId(Signal $signal) | ||
{ | ||
return $signal->userGroupId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the eZ Publish Kernel package. | ||
* | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
namespace EzSystems\PlatformHttpCacheBundle\SignalSlot; | ||
|
||
use eZ\Publish\Core\SignalSlot\Signal; | ||
|
||
/** | ||
* A slot handling CreateUserSlot. | ||
*/ | ||
class CreateUserSlot extends AbstractPublishSlot | ||
{ | ||
protected function supports(Signal $signal) | ||
{ | ||
return $signal instanceof Signal\UserService\CreateUserSignal; | ||
} | ||
|
||
protected function getContentId(Signal $signal) | ||
{ | ||
return $signal->userId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the eZ Publish Kernel package. | ||
* | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
namespace EzSystems\PlatformHttpCacheBundle\SignalSlot; | ||
|
||
use eZ\Publish\Core\SignalSlot\Signal; | ||
|
||
/** | ||
* A slot handling UpdateUserGroupSignal. | ||
*/ | ||
class UpdateUserGroupSlot extends AbstractPublishSlot | ||
{ | ||
protected function supports(Signal $signal) | ||
{ | ||
return $signal instanceof Signal\UserService\UpdateUserGroupSignal; | ||
} | ||
|
||
protected function getContentId(Signal $signal) | ||
{ | ||
return $signal->userGroupId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the eZ Publish Kernel package. | ||
* | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
namespace EzSystems\PlatformHttpCacheBundle\Tests\SignalSlot; | ||
|
||
use eZ\Publish\SPI\Persistence\Content\Location; | ||
use eZ\Publish\SPI\Persistence\Content\Location\Handler; | ||
|
||
abstract class AbstractPublishSlotTest extends AbstractContentSlotTest | ||
{ | ||
protected $locationId = 45; | ||
protected $parentLocationId = 32; | ||
|
||
/** @var \eZ\Publish\SPI\Persistence\Content\Location\Handler|\PHPUnit_Framework_MockObject_MockObject */ | ||
protected $spiLocationHandlerMock; | ||
|
||
protected function createSlot() | ||
{ | ||
$class = $this->getSlotClass(); | ||
if ($this->spiLocationHandlerMock === null) { | ||
$this->spiLocationHandlerMock = $this->createMock(Handler::class); | ||
} | ||
|
||
return new $class($this->purgeClientMock, $this->spiLocationHandlerMock); | ||
} | ||
|
||
/** | ||
* @dataProvider getUnreceivedSignals | ||
*/ | ||
public function testDoesNotReceiveOtherSignals($signal) | ||
{ | ||
$this->purgeClientMock->expects($this->never())->method('purge'); | ||
$this->purgeClientMock->expects($this->never())->method('purgeAll'); | ||
|
||
$this->spiLocationHandlerMock->expects($this->never())->method('loadLocationsByContent'); | ||
|
||
$this->slot->receive($signal); | ||
} | ||
|
||
/** | ||
* @dataProvider getReceivedSignals | ||
*/ | ||
public function testReceivePurgesCacheForTags($signal) | ||
{ | ||
$this->spiLocationHandlerMock | ||
->expects($this->once()) | ||
->method('loadLocationsByContent') | ||
->with($this->contentId) | ||
->willReturn( | ||
[ | ||
new Location([ | ||
'id' => $this->locationId, | ||
'parentId' => $this->parentLocationId, | ||
]), | ||
] | ||
); | ||
|
||
$this->purgeClientMock->expects($this->once())->method('purge')->with($this->generateTags()); | ||
$this->purgeClientMock->expects($this->never())->method('purgeAll'); | ||
parent::receive($signal); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the eZ Publish Kernel package. | ||
* | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
namespace EzSystems\PlatformHttpCacheBundle\Tests\SignalSlot; | ||
|
||
use eZ\Publish\Core\SignalSlot\Signal\UserService\CreateUserGroupSignal; | ||
use EzSystems\PlatformHttpCacheBundle\SignalSlot\CreateUserGroupSlot; | ||
|
||
class CreateUserGroupSlotTest extends AbstractPublishSlotTest | ||
{ | ||
public function createSignal() | ||
{ | ||
return new CreateUserGroupSignal([ | ||
'userGroupId' => $this->contentId, | ||
]); | ||
} | ||
|
||
public function getReceivedSignalClasses() | ||
{ | ||
return [CreateUserGroupSignal::class]; | ||
} | ||
|
||
public function getSlotClass() | ||
{ | ||
return CreateUserGroupSlot::class; | ||
} | ||
} |
Oops, something went wrong.