vendor/sulu/sulu/src/Sulu/Bundle/PageBundle/Search/EventListener/PermissionListener.php line 47

  1. <?php
  2. /*
  3.  * This file is part of Sulu.
  4.  *
  5.  * (c) Sulu GmbH
  6.  *
  7.  * This source file is subject to the MIT license that is bundled
  8.  * with this source code in the file LICENSE.
  9.  */
  10. namespace Sulu\Bundle\PageBundle\Search\EventListener;
  11. use Massive\Bundle\SearchBundle\Search\SearchManagerInterface;
  12. use Sulu\Component\Content\Document\Behavior\SecurityBehavior;
  13. use Sulu\Component\DocumentManager\DocumentManagerInterface;
  14. use Sulu\Component\Security\Event\PermissionUpdateEvent;
  15. use Sulu\Component\Security\Event\SecurityEvents;
  16. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  17. /**
  18.  * Removes a document from the index, as soon as it gets secured.
  19.  */
  20. class PermissionListener implements EventSubscriberInterface
  21. {
  22.     public function __construct(
  23.         private DocumentManagerInterface $documentManager,
  24.         private SearchManagerInterface $searchManager,
  25.     ) {
  26.     }
  27.     public static function getSubscribedEvents(): array
  28.     {
  29.         return [SecurityEvents::PERMISSION_UPDATE => 'onPermissionUpdate'];
  30.     }
  31.     public function onPermissionUpdate(PermissionUpdateEvent $permissionUpdateEvent)
  32.     {
  33.         if (SecurityBehavior::class !== $permissionUpdateEvent->getType()) {
  34.             return;
  35.         }
  36.         $document $this->documentManager->find($permissionUpdateEvent->getIdentifier());
  37.         $this->searchManager->deindex($document);
  38.     }
  39. }