|
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
|
|
|
use Symfony\Component\Filesystem\LockHandler; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Send Newsletter via email. |
|
12
|
|
|
* |
|
13
|
|
|
* @author dominik |
|
14
|
|
|
*/ |
|
15
|
|
|
class SendNewsLetterCommand extends ContainerAwareCommand |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* (non-PHPdoc). |
|
19
|
|
|
* |
|
20
|
|
|
* @see Symfony\Component\Console\Command.Command::configure() |
|
21
|
|
|
*/ |
|
22
|
3 |
|
protected function configure() |
|
23
|
|
|
{ |
|
24
|
3 |
|
$this->setName('emails:sendNewsletter') |
|
25
|
3 |
|
->setDescription('Send Newsletter via email to all subscribers.') |
|
26
|
3 |
|
->setHelp(<<<EOF |
|
27
|
3 |
|
The <info>emails:sendNewsletter</info> command sends the newsletter email to all recipients who |
|
28
|
|
|
indicate that they would like to recieve the newsletter (see Azine\EmailBundle\Entity\RecipientInterface.getNewsletter). |
|
29
|
|
|
|
|
30
|
|
|
Depending on you Swiftmailer-Configuration the email will be send directly or will be written to the spool. |
|
31
|
|
|
|
|
32
|
|
|
If you configured Swiftmailer to spool email, then you need to run the <info>swiftmailer:spool:send</info> |
|
33
|
|
|
command to actually send the emails from the spool. |
|
34
|
|
|
|
|
35
|
|
|
EOF |
|
36
|
|
|
) |
|
37
|
|
|
; |
|
38
|
3 |
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* (non-PHPdoc). |
|
42
|
|
|
* |
|
43
|
|
|
* @see Symfony\Component\Console\Command.Command::execute() |
|
44
|
|
|
*/ |
|
45
|
2 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
46
|
|
|
{ |
|
47
|
|
|
// create the lock |
|
48
|
2 |
|
$lock = new LockHandler($this->getName()); |
|
|
|
|
|
|
49
|
2 |
|
if (!$lock->lock()) { |
|
50
|
|
|
$output->writeln('The command is already running in another process.'); |
|
51
|
|
|
|
|
52
|
|
|
return 0; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
2 |
|
$failedAddresses = array(); |
|
56
|
2 |
|
$output->writeln(date(\DateTime::RFC2822).' : starting to send newsletter emails.'); |
|
57
|
|
|
|
|
58
|
2 |
|
$sentMails = $this->getContainer()->get('azine_email_notifier_service')->sendNewsletter($failedAddresses); |
|
59
|
|
|
|
|
60
|
2 |
|
$output->writeln(date(\DateTime::RFC2822).' : '.str_pad($sentMails, 4, ' ', STR_PAD_LEFT).' newsletter emails have been sent.'); |
|
61
|
2 |
|
if (sizeof($failedAddresses) > 0) { |
|
62
|
1 |
|
$output->writeln(date(\DateTime::RFC2822).' : '.'The following email-addresses failed:'); |
|
63
|
1 |
|
foreach ($failedAddresses as $address) { |
|
64
|
1 |
|
$output->writeln(' '.$address); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
2 |
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.