-
-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Petition] add reminder command (#11414)
- Loading branch information
Showing
6 changed files
with
125 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Migrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
final class Version20250131151354 extends AbstractMigration | ||
{ | ||
public function up(Schema $schema): void | ||
{ | ||
$this->addSql('ALTER TABLE petition_signature ADD reminded_at DATETIME DEFAULT NULL'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
$this->addSql('ALTER TABLE petition_signature DROP reminded_at'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace App\Command; | ||
|
||
use App\Renaissance\Petition\SignatureManager; | ||
use App\Repository\PetitionSignatureRepository; | ||
use Symfony\Component\Console\Attribute\AsCommand; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
#[AsCommand( | ||
name: 'app:petition:remind-signature', | ||
description: 'Remind unconfirmed petition signatures', | ||
)] | ||
class RemindUnconfirmedPetitionSignatureCommand extends Command | ||
{ | ||
public function __construct( | ||
private readonly PetitionSignatureRepository $repository, | ||
private readonly SignatureManager $manager, | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
public function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
foreach ($this->repository->findAllToRemind() as $signature) { | ||
$this->manager->remind($signature); | ||
} | ||
|
||
return self::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/Mailer/Message/Renaissance/PetitionConfirmationReminderMessage.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace App\Mailer\Message\Renaissance; | ||
|
||
use App\Entity\PetitionSignature; | ||
use App\Mailer\Message\Message; | ||
use Ramsey\Uuid\Uuid; | ||
|
||
class PetitionConfirmationReminderMessage extends AbstractRenaissanceMessage | ||
{ | ||
public static function create(PetitionSignature $signature, string $url): Message | ||
{ | ||
return new self( | ||
Uuid::uuid4(), | ||
$signature->emailAddress, | ||
$signature->getFullName(), | ||
'Confirmez votre signature à la pétition', | ||
[ | ||
'first_name' => $signature->firstName, | ||
'petition_name' => $signature->petitionName, | ||
'primary_link' => $url, | ||
], | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace App\Repository; | ||
|
||
use App\Entity\PetitionSignature; | ||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; | ||
use Doctrine\Persistence\ManagerRegistry; | ||
|
||
class PetitionSignatureRepository extends ServiceEntityRepository | ||
{ | ||
public function __construct(ManagerRegistry $registry) | ||
{ | ||
parent::__construct($registry, PetitionSignature::class); | ||
} | ||
|
||
/** | ||
* @return PetitionSignature[] | ||
*/ | ||
public function findAllToRemind(): array | ||
{ | ||
return $this->createQueryBuilder('ps') | ||
->where('ps.validatedAt IS NULL AND ps.remindedAt IS NULL') | ||
->andWhere('ps.createdAt < :date') | ||
->setParameter('date', new \DateTime('-1 week')) | ||
->getQuery() | ||
->getResult() | ||
; | ||
} | ||
} |