src/Aqarmap/Bundle/ListingBundle/EventListener/ListingUpdatedListener.php line 43
<?php
namespace Aqarmap\Bundle\ListingBundle\EventListener;
use App\Message\ListingUpdatedMessage;
use Aqarmap\Bundle\ListingBundle\Event\ListingUpdatedEvent;
use Aqarmap\Bundle\ListingBundle\Service\ListingLabelQueueProducer;
use Aqarmap\Bundle\ListingBundle\Service\ListingRateService;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\UnitOfWork;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Messenger\MessageBusInterface;
class ListingUpdatedListener implements EventSubscriberInterface
{
/** @var UnitOfWork */
private $unitOfWork;
public function __construct(private readonly ListingRateService $listingRateService, EntityManagerInterface $entityManager, private readonly ListingLabelQueueProducer $listingLabelQueueProducer, private readonly MessageBusInterface $messageBus)
{
$this->unitOfWork = $entityManager->getUnitOfWork();
}
public function postUpdate($listing, $event): void
{
$this->messageBus->dispatch(new ListingUpdatedMessage($listing->getId()));
$this->unitOfWork->computeChangeSets();
$changedFields = $this->unitOfWork->getEntityChangeSet($listing);
$this->listingLabelQueueProducer->publish($listing, array_keys($changedFields));
}
public function onUpdate(ListingUpdatedEvent $event): void
{
$this->listingRateService->markRateStatusUpdated($event->getListing(), $event->getFields());
}
/**
* {@inheri tdoc}.
*/
public static function getSubscribedEvents(): array
{
return [
ListingUpdatedEvent::UPDATED => 'onUpdate',
];
}
}