<?php
namespace App\EventSubscriber;
use App\Entity\JobQueue;
use App\Service\EsJobQueue;
use App\Event\CompanyPostUpdateEvent;
use App\Event\CompanyPostPersistEvent;
use Doctrine\ORM\EntityManagerInterface;
use App\Service\JobQueueAction\AttachCompanyToUserAction;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class CompanySubscriber implements EventSubscriberInterface
{
public function __construct(
private EntityManagerInterface $_em,
private EsJobQueue $esJobQueue
) {
}
public static function getSubscribedEvents(): array
{
return [
CompanyPostPersistEvent::NAME => 'postPersist',
// CompanyPostUpdateEvent::NAME => 'postUpdate'
];
}
public function postPersist(CompanyPostPersistEvent $event)
{
$data = $event->getObject();
$payload = ['companyId' => $data->getId()];
$this->esJobQueue->create(
AttachCompanyToUserAction::NAME,
json_encode($payload),
JobQueue::PRIORITY_LOW
);
}
public function postUpdate(CompanyPostUpdateEvent $event)
{
// $data = $event->getObject();
}
}