1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @author Markus Tacker <[email protected]> |
5
|
|
|
* @copyright 2013-2016 Verein zur Förderung der Netzkultur im Rhein-Main-Gebiet e.V. | http://netzkultur-rheinmain.de/ |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace BCRM\BackendBundle\Command; |
9
|
|
|
|
10
|
|
|
use BCRM\BackendBundle\Entity\Event\Event; |
11
|
|
|
use BCRM\BackendBundle\Exception\CommandException; |
12
|
|
|
use BCRM\BackendBundle\Service\Event\SendTicketMailCommand; |
13
|
|
|
use Doctrine\Common\Util\Debug; |
14
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
15
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
16
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
17
|
|
|
|
18
|
|
|
class SendTicketsMailCommand extends ContainerAwareCommand |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var OutputInterface |
22
|
|
|
*/ |
23
|
|
|
private $output; |
24
|
|
|
|
25
|
|
|
protected function configure() |
26
|
|
|
{ |
27
|
|
|
$this |
28
|
|
|
->setName('bcrm:tickets:send') |
29
|
|
|
->setDescription('Send tickets'); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
33
|
|
|
{ |
34
|
|
|
$this->output = $output; |
35
|
|
|
/** @var \BCRM\BackendBundle\Entity\Event\RegistrationRepository $registrationRepo */ |
36
|
|
|
/** @var \BCRM\BackendBundle\Entity\Event\EventRepository $eventRepo */ |
37
|
|
|
$eventRepo = $this->getContainer()->get('bcrm.backend.repo.event'); |
38
|
|
|
$event = $eventRepo->getNextEvent()->getOrThrow(new CommandException('No event.')); |
39
|
|
|
$this->sendNewTicketNotificationsFor($event); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
View Code Duplication |
protected function sendNewTicketNotificationsFor(Event $event) |
|
|
|
|
43
|
|
|
{ |
44
|
|
|
/** @var \BCRM\BackendBundle\Entity\Event\TicketRepository $repo */ |
45
|
|
|
$repo = $this->getContainer()->get('bcrm.backend.repo.ticket'); |
46
|
|
|
/** @var \LiteCQRS\Bus\CommandBus $commandBus */ |
47
|
|
|
$commandBus = $this->getContainer()->get('command_bus'); |
48
|
|
|
foreach ($repo->getToNotify($event) as $ticket) { |
49
|
|
|
if ($this->output->getVerbosity() > OutputInterface::VERBOSITY_NORMAL) { |
50
|
|
|
$this->output->writeln(sprintf('Sending ticket notification for %s', $ticket)); |
51
|
|
|
} |
52
|
|
|
$command = new SendTicketMailCommand(); |
53
|
|
|
$command->ticket = $ticket; |
54
|
|
|
$command->event = $event; |
|
|
|
|
55
|
|
|
$command->schemeAndHost = $this->getContainer()->getParameter('scheme_and_host'); |
56
|
|
|
$commandBus->handle($command); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.