From 1bfc464f38018093bbe726f06dba7e2d38dfe989 Mon Sep 17 00:00:00 2001 From: Bartek Wajda Date: Wed, 13 Dec 2023 17:56:01 +0100 Subject: [PATCH] IBX-7346: Handled trash emptying --- .../EventSubscriber/TrashEventSubscriber.php | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/eZ/Publish/Core/Search/Common/EventSubscriber/TrashEventSubscriber.php b/eZ/Publish/Core/Search/Common/EventSubscriber/TrashEventSubscriber.php index 545a3028a0..ea5c2d53c1 100644 --- a/eZ/Publish/Core/Search/Common/EventSubscriber/TrashEventSubscriber.php +++ b/eZ/Publish/Core/Search/Common/EventSubscriber/TrashEventSubscriber.php @@ -7,6 +7,7 @@ namespace eZ\Publish\Core\Search\Common\EventSubscriber; use eZ\Publish\API\Repository\Events\Trash\DeleteTrashItemEvent; +use eZ\Publish\API\Repository\Events\Trash\EmptyTrashEvent; use eZ\Publish\API\Repository\Events\Trash\RecoverEvent; use eZ\Publish\API\Repository\Events\Trash\TrashEvent; use eZ\Publish\API\Repository\Values\Content\TrashItem; @@ -16,17 +17,13 @@ class TrashEventSubscriber extends AbstractSearchEventSubscriber implements EventSubscriberInterface { - public function __construct(SearchHandler $searchHandler, PersistenceHandler $persistenceHandler) - { - parent::__construct($searchHandler, $persistenceHandler); - } - public static function getSubscribedEvents(): array { return [ RecoverEvent::class => 'onRecover', TrashEvent::class => 'onTrash', DeleteTrashItemEvent::class => 'onDeleteTrashItem', + EmptyTrashEvent::class => 'onEmptyTrashEvent', ]; } @@ -60,4 +57,21 @@ public function onDeleteTrashItem(DeleteTrashItemEvent $event): void $this->searchHandler->indexContent($persistenceContent); } } + + public function onEmptyTrashEvent(EmptyTrashEvent $event): void + { + $contentHandler = $this->persistenceHandler->contentHandler(); + + $results = $event->getResultList()->getIterator(); + + /** @var \eZ\Publish\API\Repository\Values\Content\Trash\TrashItemDeleteResult $result */ + foreach ($results as $result) { + $reverseRelationContentIds = $result->reverseRelationContentIds; + foreach ($reverseRelationContentIds as $contentId) { + $persistenceContent = $contentHandler->load($contentId); + + $this->searchHandler->indexContent($persistenceContent); + } + } + } }