src/EventSubscriber/CommonCategorySubscriber.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Entity\JobQueue;
  4. use App\Service\EsJobQueue;
  5. use App\Event\CommonCategoryPreRemoveEvent;
  6. use App\Event\CommonCategoryPostUpdateEvent;
  7. use App\Service\JobQueueAction\ElasticDependentUpdateAction;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. class CommonCategorySubscriber implements EventSubscriberInterface
  10. {
  11.     public function __construct(
  12.         private EsJobQueue $esJobQueue
  13.     ) {}
  14.     public static function getSubscribedEvents(): array
  15.     {
  16.         return [
  17.             CommonCategoryPostUpdateEvent::NAME => 'onPostUpdate',
  18.             CommonCategoryPreRemoveEvent::NAME => 'onPreRemove'
  19.         ];
  20.     }
  21.     public function onPostUpdate(CommonCategoryPostUpdateEvent $event)
  22.     {
  23.         $object $event->getObject();
  24.         $payload = [...$object->getQueueInfo(), 'operation' => 'UPDATE'];
  25.         $this->esJobQueue->create(
  26.             ElasticDependentUpdateAction::NAME,
  27.             json_encode($payload),
  28.             JobQueue::PRIORITY_LOW,
  29.             null,
  30.             1,
  31.             null,
  32.             false,
  33.             false
  34.         );
  35.     }
  36.     public function onPreRemove(CommonCategoryPreRemoveEvent $event)
  37.     {
  38.         $object $event->getObject();
  39.         $payload = [...$object->getQueueInfo(), 'operation' => 'DELETE'];
  40.         $this->esJobQueue->create(
  41.             ElasticDependentUpdateAction::NAME,
  42.             json_encode($payload),
  43.             JobQueue::PRIORITY_LOW
  44.         );
  45.     }
  46. }