feat: integrate with MailJet API for newsletter registration
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user