|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ConferenceTools\Tickets\Cli\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Carnage\Cqrs\MessageBus\MessageBusInterface; |
|
6
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
7
|
|
|
use ConferenceTools\Tickets\Domain\Command\Ticket\TimeoutPurchase; |
|
8
|
|
|
use ConferenceTools\Tickets\Domain\ReadModel\TicketRecord\PurchaseRecord; |
|
9
|
|
|
use ConferenceTools\Tickets\Domain\ReadModel\TicketRecord\TicketRecord; |
|
10
|
|
|
use Symfony\Component\Console\Command\Command; |
|
11
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
13
|
|
|
|
|
14
|
|
|
class TimeoutPurchases extends Command |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var EntityManagerInterface |
|
18
|
|
|
*/ |
|
19
|
|
|
private $em; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var MessageBusInterface |
|
23
|
|
|
*/ |
|
24
|
|
|
private $commandBus; |
|
25
|
|
|
|
|
26
|
|
|
public static function build(EntityManagerInterface $em, MessageBusInterface $commandBus) |
|
27
|
|
|
{ |
|
28
|
|
|
$instance = new static(); |
|
29
|
|
|
$instance->em = $em; |
|
30
|
|
|
$instance->commandBus = $commandBus; |
|
31
|
|
|
|
|
32
|
|
|
return $instance; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
protected function configure() |
|
36
|
|
|
{ |
|
37
|
|
|
$this->setName('tickets:timeout-purchases') |
|
38
|
|
|
->setDescription('Times out all purchases over 30 mins old.'); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
42
|
|
|
{ |
|
43
|
|
|
$qb = $this->em->getRepository(PurchaseRecord::class)->createQueryBuilder('pr'); |
|
44
|
|
|
/** @var PurchaseRecord[] $timedout */ |
|
45
|
|
|
$timedout = $qb->where('pr.paid = false') |
|
46
|
|
|
->getQuery() |
|
47
|
|
|
->getResult(); |
|
48
|
|
|
|
|
49
|
|
|
foreach ($timedout as $ticketRecord) { |
|
50
|
|
|
if ($ticketRecord->hasTimedout()) { |
|
51
|
|
|
$command = new TimeoutPurchase($ticketRecord->getPurchaseId()); |
|
52
|
|
|
$this->commandBus->dispatch($command); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
} |