src/EventListener/GlossaryEventListener.php line 43

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use App\Services\ElasticModelFactory;
  4. use App\Services\ElasticsearchService;
  5. use Pimcore\Event\Model\DocumentEvent;
  6. class GlossaryEventListener
  7. {
  8.     /**
  9.      * @param DocumentEvent $event
  10.      * @return void
  11.      */
  12.     public function elasticsearchReindex(DocumentEvent $event)
  13.     {
  14.         $document $event->getDocument();
  15.         if (!method_exists($document'getController') || !method_exists($document'getTemplate')) return;
  16.         if (
  17.             $document->getController() != 'App\Controller\Glossary\GlossaryController::glossarySingleAction' &&
  18.             $document->getTemplate() != 'glossary/glossary_single.html.twig'
  19.         ) return;
  20.         $elasticService = new ElasticsearchService();
  21.         $elasticFactory = new ElasticModelFactory();
  22.         $elasticModel $elasticFactory->make($document);
  23.         if (!$document->getPublished()) {
  24.             $elasticService->delete($elasticModel);
  25.         } else {
  26.             $elasticService->update($elasticModel);
  27.         }
  28.     }
  29.     /**
  30.      * @param DocumentEvent $event
  31.      * @return void
  32.      */
  33.     public function elasticsearchDelete(DocumentEvent $event)
  34.     {
  35.         $document $event->getDocument();
  36.         if (!method_exists($document'getController') || !method_exists($document'getTemplate')) return;
  37.         if (
  38.             $document->getController() != 'App\Controller\Glossary\GlossaryController::glossarySingleAction' &&
  39.             $document->getTemplate() != 'glossary/glossary_single.html.twig'
  40.         ) return;
  41.         $elasticService = new ElasticsearchService();
  42.         $elasticFactory = new ElasticModelFactory();
  43.         $elasticModel $elasticFactory->make($document);
  44.         $elasticService->delete($elasticModel);
  45.     }
  46. }