src/EventSubscriber/SearchManagement/DciSubscriber.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber\SearchManagement;
  3. use App\Event\SearchManagement\DciEvent;
  4. use App\Repository\SearchManagement\IndexationRepository;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. class DciSubscriber implements EventSubscriberInterface
  8. {
  9.     private $manager;
  10.     private $indexationRepository;
  11.     public function __construct(EntityManagerInterface $managerIndexationRepository $indexationRepository)
  12.     {
  13.         $this->indexationRepository $indexationRepository;
  14.         $this->manager $manager;        
  15.     }
  16.     public static function getSubscribedEvents()
  17.     {
  18.         return [
  19.             DciEvent::DESINDEXER => 'desIndexser',
  20.         ];
  21.     }
  22.     public function desIndexser(DciEvent $event)
  23.     {
  24.         $dci $event->getDci();
  25.         $indexs $this->indexationRepository->findBy(['dci' => $dci]);
  26.         foreach ($indexs as $index) {
  27.             $this->manager->remove($index);
  28.         }
  29.         $this->manager->flush();
  30.     }   
  31. }