<?php declare(strict_types=1);
namespace Shopware\Core\Content\Newsletter\Event\Subscriber;
use Shopware\Core\Content\Newsletter\DataAbstractionLayer\NewsletterRecipientIndexingMessage;
use Shopware\Core\Content\Newsletter\NewsletterEvents;
use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityDeletedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Messenger\MessageBusInterface;
class NewsletterRecipientDeletedSubscriber implements EventSubscriberInterface
{
private MessageBusInterface $messageBus;
public function __construct(MessageBusInterface $messageBus)
{
$this->messageBus = $messageBus;
}
public static function getSubscribedEvents()
{
return [NewsletterEvents::NEWSLETTER_RECIPIENT_DELETED_EVENT => 'onNewsletterRecipientDeleted'];
}
public function onNewsletterRecipientDeleted(EntityDeletedEvent $event): void
{
$message = new NewsletterRecipientIndexingMessage($event->getIds(), null, $event->getContext());
$message->setDeletedNewsletterRecipients(true);
$this->messageBus->dispatch($message);
}
}