1 | <?php |
||
2 | |||
3 | namespace Azine\EmailBundle\Command; |
||
4 | |||
5 | use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
||
6 | use Symfony\Component\Console\Input\InputInterface; |
||
7 | use Symfony\Component\Console\Output\OutputInterface; |
||
8 | |||
9 | /** |
||
10 | * Send Newsletter via email. |
||
11 | * |
||
12 | * @author dominik |
||
13 | */ |
||
14 | class SendNewsLetterCommand extends ContainerAwareCommand |
||
0 ignored issues
–
show
Deprecated Code
introduced
by
![]() |
|||
15 | { |
||
16 | /** |
||
17 | * (non-PHPdoc). |
||
18 | * |
||
19 | * @see Symfony\Component\Console\Command.Command::configure() |
||
20 | */ |
||
21 | protected function configure() |
||
22 | 3 | { |
|
23 | $this->setName('emails:sendNewsletter') |
||
24 | 3 | ->setDescription('Send Newsletter via email to all subscribers.') |
|
25 | 3 | ->setHelp(<<<EOF |
|
26 | 3 | The <info>emails:sendNewsletter</info> command sends the newsletter email to all recipients who |
|
27 | 3 | indicate that they would like to recieve the newsletter (see Azine\EmailBundle\Entity\RecipientInterface.getNewsletter). |
|
28 | |||
29 | Depending on you Swiftmailer-Configuration the email will be send directly or will be written to the spool. |
||
30 | |||
31 | If you configured Swiftmailer to spool email, then you need to run the <info>swiftmailer:spool:send</info> |
||
32 | command to actually send the emails from the spool. |
||
33 | |||
34 | EOF |
||
35 | ) |
||
36 | ; |
||
37 | } |
||
38 | 3 | ||
39 | /** |
||
40 | * (non-PHPdoc). |
||
41 | * |
||
42 | * @see Symfony\Component\Console\Command.Command::execute() |
||
43 | */ |
||
44 | protected function execute(InputInterface $input, OutputInterface $output) |
||
45 | 2 | { |
|
46 | if (\Symfony\Component\HttpKernel\Kernel::VERSION_ID < 30400) { |
||
47 | $lock = new \Symfony\Component\Filesystem\LockHandler($this->getName()); |
||
0 ignored issues
–
show
The type
Symfony\Component\Filesystem\LockHandler was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
48 | 2 | $unlockedCommand = $lock->lock(); |
|
49 | 2 | } else { |
|
50 | $store = new \Symfony\Component\Lock\Store\SemaphoreStore(); |
||
51 | $factory = new \Symfony\Component\Lock\Factory($store); |
||
52 | |||
53 | $lock = $factory->createLock($this->getName()); |
||
54 | $unlockedCommand = $lock->acquire(); |
||
55 | 2 | } |
|
56 | 2 | ||
57 | if (!$unlockedCommand) { |
||
58 | 2 | $output->writeln('The command is already running in another process.'); |
|
59 | |||
60 | 2 | return 0; |
|
61 | 2 | } |
|
62 | 1 | ||
63 | 1 | $failedAddresses = array(); |
|
64 | 1 | $output->writeln(date(\DateTime::RFC2822).' : starting to send newsletter emails.'); |
|
65 | |||
66 | $sentMails = $this->getContainer()->get('azine_email_notifier_service')->sendNewsletter($failedAddresses); |
||
67 | 2 | ||
68 | $output->writeln(date(\DateTime::RFC2822).' : '.str_pad($sentMails, 4, ' ', STR_PAD_LEFT).' newsletter emails have been sent.'); |
||
69 | if (sizeof($failedAddresses) > 0) { |
||
70 | $output->writeln(date(\DateTime::RFC2822).' : '.'The following email-addresses failed:'); |
||
71 | foreach ($failedAddresses as $address) { |
||
72 | $output->writeln(' '.$address); |
||
73 | } |
||
74 | } |
||
75 | } |
||
76 | } |
||
77 |