vendor/sulu/sulu/src/Sulu/Bundle/MediaBundle/Search/EventListener/PermissionListener.php line 52

Open in your IDE?
  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\MediaBundle\Search\EventListener;
  11. use Massive\Bundle\SearchBundle\Search\SearchManagerInterface;
  12. use Sulu\Bundle\MediaBundle\Entity\Collection;
  13. use Sulu\Bundle\MediaBundle\Entity\FileVersionMetaRepository;
  14. use Sulu\Component\Security\Event\PermissionUpdateEvent;
  15. use Sulu\Component\Security\Event\SecurityEvents;
  16. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  17. /**
  18.  * Removes a media from the index, as soon as it gets secured.
  19.  */
  20. class PermissionListener implements EventSubscriberInterface
  21. {
  22.     /**
  23.      * @var FileVersionMetaRepository
  24.      */
  25.     private $fileVersionMetaRepository;
  26.     /**
  27.      * @var SearchManagerInterface
  28.      */
  29.     private $searchManager;
  30.     public function __construct(
  31.         FileVersionMetaRepository $fileVersionMetaRepository,
  32.         SearchManagerInterface $searchManager
  33.     ) {
  34.         $this->fileVersionMetaRepository $fileVersionMetaRepository;
  35.         $this->searchManager $searchManager;
  36.     }
  37.     public static function getSubscribedEvents(): array
  38.     {
  39.         return [SecurityEvents::PERMISSION_UPDATE => 'onPermissionUpdate'];
  40.     }
  41.     /**
  42.      * Removes all FileVersionMetas belonging to the collection, which just got secured.
  43.      */
  44.     public function onPermissionUpdate(PermissionUpdateEvent $event)
  45.     {
  46.         if (Collection::class !== $event->getType()) {
  47.             return;
  48.         }
  49.         foreach ($this->fileVersionMetaRepository->findByCollectionId($event->getIdentifier()) as $fileVersionMeta) {
  50.             $this->searchManager->deindex($fileVersionMeta);
  51.         }
  52.     }
  53. }