-
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-30646: Reimplemented SignalSlots using EventDispatcher (#91)
- Loading branch information
1 parent
7d3b479
commit 416a15f
Showing
108 changed files
with
845 additions
and
3,644 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
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,94 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace EzSystems\PlatformHttpCacheBundle\EventSubscriber\CachePurge; | ||
|
||
use EzSystems\PlatformHttpCacheBundle\PurgeClient\PurgeClientInterface; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use eZ\Publish\SPI\Persistence\Content\Location\Handler as LocationHandler; | ||
use eZ\Publish\SPI\Persistence\URL\Handler as UrlHandler; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
abstract class AbstractSubscriber implements EventSubscriberInterface | ||
{ | ||
/** @var \EzSystems\PlatformHttpCacheBundle\PurgeClient\PurgeClientInterface */ | ||
protected $purgeClient; | ||
|
||
/** @var \eZ\Publish\SPI\Persistence\Content\Location\Handler */ | ||
private $locationHandler; | ||
|
||
/** @var \eZ\Publish\SPI\Persistence\URL\Handler */ | ||
private $urlHandler; | ||
|
||
public function __construct( | ||
PurgeClientInterface $purgeClient, | ||
LocationHandler $locationHandler, | ||
UrlHandler $urlHandler | ||
) { | ||
$this->purgeClient = $purgeClient; | ||
$this->locationHandler = $locationHandler; | ||
$this->urlHandler = $urlHandler; | ||
} | ||
|
||
public function getContentTags(int $contentId): array | ||
{ | ||
return [ | ||
'content-' . $contentId, | ||
'relation-' . $contentId, | ||
]; | ||
} | ||
|
||
public function getLocationTags(int $locationId): array | ||
{ | ||
return [ | ||
'location-' . $locationId, | ||
'parent-' . $locationId, | ||
'relation-location-' . $locationId, | ||
]; | ||
} | ||
|
||
public function getParentLocationTags(int $locationId): array | ||
{ | ||
return [ | ||
'location-' . $locationId, | ||
'parent-' . $locationId, | ||
]; | ||
} | ||
|
||
public function getContentLocationsTags(int $contentId): array | ||
{ | ||
$tags = []; | ||
|
||
$locations = $this->locationHandler->loadLocationsByContent($contentId); | ||
|
||
foreach ($locations as $location) { | ||
$tags = array_merge( | ||
$tags, | ||
$this->getLocationTags($location->id), | ||
$this->getParentLocationTags($location->parentId), | ||
); | ||
} | ||
|
||
return $tags; | ||
} | ||
|
||
public function getContentUrlTags(int $urlId): array | ||
{ | ||
$tags = []; | ||
|
||
$contentIds = $this->urlHandler->findUsages($urlId); | ||
|
||
foreach ($contentIds as $contentId) { | ||
$tags[] = 'content-' . $contentId; | ||
} | ||
|
||
return $tags; | ||
} | ||
} |
134 changes: 134 additions & 0 deletions
134
src/EventSubscriber/CachePurge/ContentEventsSubscriber.php
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,134 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace EzSystems\PlatformHttpCacheBundle\EventSubscriber\CachePurge; | ||
|
||
use eZ\Publish\API\Repository\Events\Content\CopyContentEvent; | ||
use eZ\Publish\API\Repository\Events\Content\CreateContentDraftEvent; | ||
use eZ\Publish\API\Repository\Events\Content\DeleteContentEvent; | ||
use eZ\Publish\API\Repository\Events\Content\DeleteVersionEvent; | ||
use eZ\Publish\API\Repository\Events\Content\HideContentEvent; | ||
use eZ\Publish\API\Repository\Events\Content\PublishVersionEvent; | ||
use eZ\Publish\API\Repository\Events\Content\RevealContentEvent; | ||
use eZ\Publish\API\Repository\Events\Content\UpdateContentEvent; | ||
use eZ\Publish\API\Repository\Events\Content\UpdateContentMetadataEvent; | ||
|
||
final class ContentEventsSubscriber extends AbstractSubscriber | ||
{ | ||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
CopyContentEvent::class => 'onCopyContentEvent', | ||
CreateContentDraftEvent::class => 'onCreateContentDraftEvent', | ||
DeleteContentEvent::class => 'onDeleteContentEvent', | ||
DeleteVersionEvent::class => 'onDeleteVersionEvent', | ||
HideContentEvent::class => 'onHideContentEvent', | ||
PublishVersionEvent::class => 'onPublishVersionEvent', | ||
RevealContentEvent::class => 'onRevealContentEvent', | ||
UpdateContentEvent::class => 'onUpdateContentEvent', | ||
UpdateContentMetadataEvent::class => 'onUpdateContentMetadataEvent', | ||
]; | ||
} | ||
|
||
public function onCopyContentEvent(CopyContentEvent $event): void | ||
{ | ||
$contentId = $event->getContentInfo()->id; | ||
$parentLocationId = $event->getDestinationLocationCreateStruct()->parentLocationId; | ||
|
||
$this->purgeClient->purge([ | ||
'content-' . $contentId, | ||
'location-' . $parentLocationId, | ||
'path-' . $parentLocationId, | ||
]); | ||
} | ||
|
||
public function onCreateContentDraftEvent(CreateContentDraftEvent $event): void | ||
{ | ||
$contentId = $event->getContentInfo()->id; | ||
|
||
$this->purgeClient->purge([ | ||
'content-versions-' . $contentId, | ||
]); | ||
} | ||
|
||
public function onDeleteContentEvent(DeleteContentEvent $event): void | ||
{ | ||
$contentId = $event->getContentInfo()->id; | ||
|
||
$tags = $this->getContentTags($contentId); | ||
|
||
foreach ($event->getLocations() as $locationId) { | ||
$tags[] = 'path-' . $locationId; | ||
} | ||
|
||
$this->purgeClient->purge($tags); | ||
} | ||
|
||
public function onDeleteVersionEvent(DeleteVersionEvent $event): void | ||
{ | ||
$contentId = $event->getVersionInfo()->getContentInfo()->id; | ||
|
||
$this->purgeClient->purge([ | ||
'delete-versions-' . $contentId, | ||
]); | ||
} | ||
|
||
public function onHideContentEvent(HideContentEvent $event): void | ||
{ | ||
$contentId = $event->getContentInfo()->id; | ||
|
||
$tags = array_merge( | ||
$this->getContentTags($contentId), | ||
$this->getContentLocationsTags($contentId) | ||
); | ||
|
||
$this->purgeClient->purge($tags); | ||
} | ||
|
||
public function onPublishVersionEvent(PublishVersionEvent $event): void | ||
{ | ||
$contentId = $event->getContent()->getVersionInfo()->getContentInfo()->id; | ||
|
||
$tags = array_merge( | ||
$this->getContentTags($contentId), | ||
$this->getContentLocationsTags($contentId) | ||
); | ||
|
||
$this->purgeClient->purge($tags); | ||
} | ||
|
||
public function onRevealContentEvent(RevealContentEvent $event): void | ||
{ | ||
$contentId = $event->getContentInfo()->id; | ||
|
||
$tags = array_merge( | ||
$this->getContentTags($contentId), | ||
$this->getContentLocationsTags($contentId) | ||
); | ||
|
||
$this->purgeClient->purge($tags); | ||
} | ||
|
||
public function onUpdateContentEvent(UpdateContentEvent $event): void | ||
{ | ||
$contentId = $event->getContent()->getVersionInfo()->getContentInfo()->id; | ||
|
||
$this->purgeClient->purge([ | ||
'content-versions-' . $contentId, | ||
]); | ||
} | ||
|
||
public function onUpdateContentMetadataEvent(UpdateContentMetadataEvent $event): void | ||
{ | ||
$contentId = $event->getContent()->getVersionInfo()->getContentInfo()->id; | ||
|
||
$this->purgeClient->purge( | ||
$this->getContentTags($contentId) | ||
); | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
src/EventSubscriber/CachePurge/ContentTypeEventsSubscriber.php
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,87 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace EzSystems\PlatformHttpCacheBundle\EventSubscriber\CachePurge; | ||
|
||
use eZ\Publish\API\Repository\Events\ContentType\AssignContentTypeGroupEvent; | ||
use eZ\Publish\API\Repository\Events\ContentType\DeleteContentTypeEvent; | ||
use eZ\Publish\API\Repository\Events\ContentType\DeleteContentTypeGroupEvent; | ||
use eZ\Publish\API\Repository\Events\ContentType\PublishContentTypeDraftEvent; | ||
use eZ\Publish\API\Repository\Events\ContentType\UnassignContentTypeGroupEvent; | ||
use eZ\Publish\API\Repository\Events\ContentType\UpdateContentTypeGroupEvent; | ||
|
||
final class ContentTypeEventsSubscriber extends AbstractSubscriber | ||
{ | ||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
AssignContentTypeGroupEvent::class => 'onAssignContentTypeGroup', | ||
DeleteContentTypeGroupEvent::class => 'onDeleteContentTypeGroup', | ||
DeleteContentTypeEvent::class => 'onDeleteContentType', | ||
PublishContentTypeDraftEvent::class => 'onPublishContentTypeDraft', | ||
UnassignContentTypeGroupEvent::class => 'onUnassignContentTypeGroup', | ||
UpdateContentTypeGroupEvent::class => 'onUpdateContentTypeGroup', | ||
]; | ||
} | ||
|
||
public function onAssignContentTypeGroup(AssignContentTypeGroupEvent $event): void | ||
{ | ||
$contentTypeGroupId = $event->getContentTypeGroup()->id; | ||
|
||
$this->purgeClient->purge([ | ||
'type-group-' . $contentTypeGroupId, | ||
]); | ||
} | ||
|
||
public function onDeleteContentTypeGroup(DeleteContentTypeGroupEvent $event): void | ||
{ | ||
$contentTypeGroupId = $event->getContentTypeGroup()->id; | ||
|
||
$this->purgeClient->purge([ | ||
'type-group-' . $contentTypeGroupId, | ||
]); | ||
} | ||
|
||
public function onDeleteContentType(DeleteContentTypeEvent $event): void | ||
{ | ||
$contentTypeId = $event->getContentType()->id; | ||
|
||
$this->purgeClient->purge([ | ||
'content-type-' . $contentTypeId, | ||
'type-' . $contentTypeId, | ||
]); | ||
} | ||
|
||
public function onPublishContentTypeDraft(PublishContentTypeDraftEvent $event): void | ||
{ | ||
$contentTypeId = $event->getContentTypeDraft()->id; | ||
|
||
$this->purgeClient->purge([ | ||
'content-type-' . $contentTypeId, | ||
'type-' . $contentTypeId, | ||
]); | ||
} | ||
|
||
public function onUnassignContentTypeGroup(UnassignContentTypeGroupEvent $event): void | ||
{ | ||
$contentTypeGroupId = $event->getContentTypeGroup()->id; | ||
|
||
$this->purgeClient->purge([ | ||
'type-group-' . $contentTypeGroupId, | ||
]); | ||
} | ||
|
||
public function onUpdateContentTypeGroup(UpdateContentTypeGroupEvent $event): void | ||
{ | ||
$contentTypeGroupId = $event->getContentTypeGroup()->id; | ||
|
||
$this->purgeClient->purge([ | ||
'type-group-' . $contentTypeGroupId, | ||
]); | ||
} | ||
} |
Oops, something went wrong.