Skip to content

Commit

Permalink
IBX-7346: Handled trash emptying
Browse files Browse the repository at this point in the history
  • Loading branch information
barw4 committed Dec 13, 2023
1 parent 3cae277 commit 1bfc464
Showing 1 changed file with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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',
];
}

Expand Down Expand Up @@ -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);
}
}
}
}

0 comments on commit 1bfc464

Please sign in to comment.