|
1 <?php |
|
2 |
|
3 /* |
|
4 * This file is part of the Symfony package. |
|
5 * |
|
6 * (c) Fabien Potencier <fabien@symfony.com> |
|
7 * |
|
8 * For the full copyright and license information, please view the LICENSE |
|
9 * file that was distributed with this source code. |
|
10 */ |
|
11 |
|
12 namespace Symfony\Bundle\SwiftmailerBundle\Command; |
|
13 |
|
14 use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
|
15 use Symfony\Component\Console\Input\InputInterface; |
|
16 use Symfony\Component\Console\Output\OutputInterface; |
|
17 use Symfony\Component\Console\Input\InputOption; |
|
18 |
|
19 /** |
|
20 * Send Emails from the spool. |
|
21 * |
|
22 * @author Fabien Potencier <fabien@symfony.com> |
|
23 * @author Clément JOBEILI <clement.jobeili@gmail.com> |
|
24 */ |
|
25 class SendEmailCommand extends ContainerAwareCommand |
|
26 { |
|
27 /** |
|
28 * @see Command |
|
29 */ |
|
30 protected function configure() |
|
31 { |
|
32 $this |
|
33 ->setName('swiftmailer:spool:send') |
|
34 ->setDescription('Send emails from the spool') |
|
35 ->addOption('message-limit', 0, InputOption::VALUE_OPTIONAL, 'The maximum number of messages to send.') |
|
36 ->addOption('time-limit', 0, InputOption::VALUE_OPTIONAL, 'The time limit for sending messages (in seconds).') |
|
37 ->setHelp(<<<EOF |
|
38 The <info>swiftmailer:spool:send</info> command sends all emails from the spool. |
|
39 |
|
40 <info>php app/console swiftmailer:spool:send --message-limit=10 --time-limit=10</info> |
|
41 |
|
42 EOF |
|
43 ) |
|
44 ; |
|
45 } |
|
46 |
|
47 /** |
|
48 * {@inheritdoc} |
|
49 */ |
|
50 protected function execute(InputInterface $input, OutputInterface $output) |
|
51 { |
|
52 $mailer = $this->getContainer()->get('mailer'); |
|
53 $transport = $mailer->getTransport(); |
|
54 |
|
55 if ($transport instanceof \Swift_Transport_SpoolTransport) { |
|
56 $spool = $transport->getSpool(); |
|
57 $spool->setMessageLimit($input->getOption('message-limit')); |
|
58 $spool->setTimeLimit($input->getOption('time-limit')); |
|
59 $sent = $spool->flushQueue($this->getContainer()->get('swiftmailer.transport.real')); |
|
60 |
|
61 $output->writeln(sprintf('sent %s emails', $sent)); |
|
62 } |
|
63 } |
|
64 } |