fix: prevent race condition on newsletter consent confirmation

This commit is contained in:
Björn Fromme committed 2026-07-14 09:47:22 +02:00
1 parent b95944701e
commit 6c4ea07e6e
3 files changed
+39 -4

No files matched your search

@@ -38,4 +38,31 @@ class NewsletterConsentRepository extends ServiceEntityRepository
'mailjetListId' => $mailjetListId,
]);
}
/**
* @param list<int> $mailjetListIds
*
* @return array<int, NewsletterConsent> existing consents indexed by mailjetListId
*/
public function findByEmailAndListIds(string $email, array $mailjetListIds): array
{
if ([] === $mailjetListIds) {
return [];
}
$consents = $this->createQueryBuilder('c')
->where('c.email = :email')
->andWhere('c.mailjetListId IN (:listIds)')
->setParameter('email', mb_strtolower(trim($email)))
->setParameter('listIds', $mailjetListIds)
->getQuery()
->getResult();
$byListId = [];
foreach ($consents as $consent) {
$byListId[$consent->getMailjetListId()] = $consent;
}
return $byListId;
}
}