fix: prevent race condition on newsletter consent confirmation
This commit is contained in:
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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user