|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Movies\Command; |
|
4
|
|
|
|
|
5
|
|
|
use App\Movies\DTO\ReleaseDateNotificationDTO; |
|
6
|
|
|
use App\Movies\Repository\MovieReleaseDateRepository; |
|
7
|
|
|
use App\Users\Service\SendEmailService; |
|
8
|
|
|
use Symfony\Component\Console\Command\Command; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
11
|
|
|
|
|
12
|
|
|
class ReleaseDateNotifications extends Command |
|
13
|
|
|
{ |
|
14
|
|
|
/** @var $repository MovieReleaseDateRepository */ |
|
15
|
|
|
private $repository; |
|
16
|
|
|
|
|
17
|
|
|
/** @var $emailService SendEmailService */ |
|
18
|
|
|
private $emailService; |
|
19
|
|
|
|
|
20
|
|
|
public function __construct(MovieReleaseDateRepository $repository, SendEmailService $emailService, ?string $name = null) |
|
21
|
|
|
{ |
|
22
|
|
|
parent::__construct($name); |
|
23
|
|
|
|
|
24
|
|
|
$this->repository = $repository; |
|
25
|
|
|
$this->emailService = $emailService; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
protected function configure() |
|
29
|
|
|
{ |
|
30
|
|
|
$this |
|
31
|
|
|
->setName('app:release-date-notifications') |
|
32
|
|
|
->setDescription('Send release date notifications if any movies released today') |
|
33
|
|
|
->setHelp('This command will notify users about release dates'); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
37
|
|
|
{ |
|
38
|
|
|
$date = date('Y-m-d'); |
|
39
|
|
|
$rows = $this->repository->findAllByDate($date); |
|
40
|
|
|
$rows = $rows->getScalarResult(); |
|
41
|
|
|
|
|
42
|
|
|
foreach ($rows as $row) { |
|
43
|
|
|
$dto = new ReleaseDateNotificationDTO( |
|
44
|
|
|
(int) $row['m_id'], |
|
45
|
|
|
$row['m_original_title'], |
|
46
|
|
|
$row['c_name'] |
|
47
|
|
|
); |
|
48
|
|
|
$this->emailService->sendReleaseDateNotification($row['u_email'], $dto); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|