fix: prevent race condition on newsletter consent confirmation
This commit is contained in:
@@ -327,8 +327,7 @@ class NewsletterManager
|
||||
$this->newsletterService->ensureSubscribed($confirmation->getEmail(), $mailjetListId);
|
||||
}
|
||||
|
||||
$confirmation->markConfirmed();
|
||||
$this->upsertConfirmedConsents($confirmation->getEmail(), $mailjetListIds, $confirmation->getFirstName(), $confirmation->getLastName(), false, false);
|
||||
$this->upsertConfirmedConsents($confirmation->getEmail(), $mailjetListIds, $confirmation->getFirstName(), $confirmation->getLastName(), flush: false, deletePending: false);
|
||||
$this->entityManager->remove($confirmation);
|
||||
$this->entityManager->flush();
|
||||
|
||||
@@ -468,8 +467,10 @@ class NewsletterManager
|
||||
*/
|
||||
private function upsertConfirmedConsents(string $email, array $mailjetListIds, ?string $firstName, ?string $lastName, bool $flush = true, bool $deletePending = true): void
|
||||
{
|
||||
$existingByListId = $this->consentRepository->findByEmailAndListIds($email, $mailjetListIds);
|
||||
|
||||
foreach ($mailjetListIds as $mailjetListId) {
|
||||
$consent = $this->consentRepository->findOneByEmailAndListId($email, $mailjetListId);
|
||||
$consent = $existingByListId[$mailjetListId] ?? null;
|
||||
if (null === $consent) {
|
||||
$consent = new NewsletterConsent($email, $mailjetListId, $firstName, $lastName);
|
||||
$this->entityManager->persist($consent);
|
||||
|
||||
Reference in New Issue
Block a user