Repository navigation
Expand file tree
/
Copy pathCronMailCommand.php
More file actions
60 lines (53 loc) · 2.01 KB
/
Copy pathCronMailCommand.php
File metadata and controls
60 lines (53 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
// src/AppBundle/Command/CronMailCommand.php
namespace MainBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use MainBundle\Service\Mailer\MailManager;
class CronMailCommand extends ContainerAwareCommand
{
/**
* Ajoute la fonction bin/console cron:mail
*/
protected function configure()
{
$this
// bin/console
->setName('cron:mail')
->setDescription('Stocke dans le spool les mails pour les utilisateurs n\'ayant pas fait le feedback de leurs réservations')
->setHelp('Stocke dans le spool les mails pour les utilisateurs n\'ayant pas fait le feedback de leurs réservations')
;
}
/**
* Envoie les mails aux utilisateurs n'ayant pas fait leurs feedback
* @param InputInterface $input
* @param OutputInterface $output
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$doctrine = $this->getContainer()->get('doctrine');
$reservations = $doctrine->getRepository('MainBundle:Reservation')
->findFeedbackableReservations();
//Commentaire
$output->writeln([
'============',
'Envoi des emails en cours',
]);
foreach ($reservations as $reservation){
//Stockage du mail dans le spool
$mailManager = new MailManager($this->getContainer());
$mailManager->sendMailDemandeFeedback($reservation);
//On met à true pour que le mail ne soit pas envoyé plusieurs fois
//et que l'utilisateur aie le droit de replir sont feedback
$reservation->setIsFeedbackable(true);
//On commit
$doctrine->getManager()->flush();
}
$output->writeln([
'Envoi des emails terminé',
sizeof($reservations) . ' mails envoyés',
'============',
]);
}
}