feat: MailJet list handling with DOI, webhook receiver and API endpoint
addresses #869cut134
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\MessageHandler;
|
||||
|
||||
use App\Entity\NewsletterConsent;
|
||||
use App\Message\MailjetNewsletterEventMessage;
|
||||
use App\Repository\NewsletterConsentRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||
|
||||
#[AsMessageHandler]
|
||||
final class MailjetNewsletterEventHandler
|
||||
{
|
||||
public function __construct(
|
||||
private readonly NewsletterConsentRepository $consentRepository,
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(MailjetNewsletterEventMessage $message): void
|
||||
{
|
||||
if (MailjetNewsletterEventMessage::EVENT_UNSUBSCRIBE !== $message->event) {
|
||||
return;
|
||||
}
|
||||
|
||||
$consent = $this->consentRepository->findOneByEmailAndListId($message->email, $message->mailjetListId);
|
||||
if (null === $consent) {
|
||||
$consent = new NewsletterConsent($message->email, $message->mailjetListId);
|
||||
$this->entityManager->persist($consent);
|
||||
}
|
||||
|
||||
$revokedAt = $message->eventAt ?? new \DateTimeImmutable();
|
||||
if (null === $message->eventAt && null !== $consent->getRevokedAt()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (null !== $message->eventAt && null !== $consent->getConfirmedAt() && $consent->getConfirmedAt() > $message->eventAt) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (null !== $consent->getRevokedAt() && $consent->getRevokedAt() >= $revokedAt) {
|
||||
return;
|
||||
}
|
||||
|
||||
$consent->markRevoked($revokedAt);
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user