feat: integrate with MailJet API for newsletter registration

This commit is contained in:
Björn Fromme
2026-03-19 09:42:00 +01:00
parent 66c55f0722
commit d1e2bf3e7d
26 changed files with 1537 additions and 47 deletions
@@ -0,0 +1,65 @@
<?php
declare(strict_types=1);
namespace App\Repository;
use App\Entity\NewsletterOptInConfirmation;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<NewsletterOptInConfirmation>
*/
class NewsletterOptInConfirmationRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, NewsletterOptInConfirmation::class);
}
public function findByTokenHash(string $tokenHash): ?NewsletterOptInConfirmation
{
return $this->findOneBy(['tokenHash' => $tokenHash]);
}
public function findPendingByEmail(string $email): ?NewsletterOptInConfirmation
{
return $this->createQueryBuilder('c')
->where('c.email = :email')
->andWhere('c.confirmedAt IS NULL')
->andWhere('c.expiresAt > :now')
->setParameter('email', mb_strtolower(trim($email)))
->setParameter('now', new \DateTimeImmutable())
->orderBy('c.createdAt', 'DESC')
->setMaxResults(1)
->getQuery()
->getOneOrNullResult();
}
public function deleteExpiredPendingByEmail(string $email): int
{
return (int) $this->createQueryBuilder('c')
->delete()
->where('c.email = :email')
->andWhere('c.confirmedAt IS NULL')
->andWhere('c.expiresAt <= :now')
->setParameter('email', mb_strtolower(trim($email)))
->setParameter('now', new \DateTimeImmutable())
->getQuery()
->execute();
}
public function deleteExpiredPending(): int
{
$threshold = new \DateTimeImmutable();
return (int) $this->createQueryBuilder('c')
->delete()
->where('c.confirmedAt IS NULL')
->andWhere('c.expiresAt <= :threshold')
->setParameter('threshold', $threshold)
->getQuery()
->execute();
}
}