merged branch timewasted/patch-1 (PR #3158)

Commits
-------

9e55cda Only call recover() when spool is a Swift_FileSpool
d2a0c74 Use if/else instead of ternary operator
15c666b Add a "recover-timeout" option to allow recovering messages that have taken too long to send

Discussion
----------

[SwiftmailerBundle] Add a "recover-timeout" option to swiftmailer:spool:send

This would allow for easy resending of messages that were marked as being sent, but for whatever reason were never actually sent.
This commit is contained in:
Fabien Potencier 2012-01-22 09:38:58 +01:00
commit 09694999b8

View File

@ -34,10 +34,11 @@ class SendEmailCommand extends ContainerAwareCommand
->setDescription('Sends emails from the spool')
->addOption('message-limit', 0, InputOption::VALUE_OPTIONAL, 'The maximum number of messages to send.')
->addOption('time-limit', 0, InputOption::VALUE_OPTIONAL, 'The time limit for sending messages (in seconds).')
->addOption('recover-timeout', 0, InputOption::VALUE_OPTIONAL, 'The timeout for recovering messages that have taken too long to send (in seconds).')
->setHelp(<<<EOF
The <info>swiftmailer:spool:send</info> command sends all emails from the spool.
<info>php app/console swiftmailer:spool:send --message-limit=10 --time-limit=10</info>
<info>php app/console swiftmailer:spool:send --message-limit=10 --time-limit=10 --recover-timeout=900</info>
EOF
)
@ -58,6 +59,13 @@ EOF
$spool->setMessageLimit($input->getOption('message-limit'));
$spool->setTimeLimit($input->getOption('time-limit'));
}
if ($spool instanceof \Swift_FileSpool) {
if (null !== $input->getOption('recover-timeout')) {
$spool->recover($input->getOption('recover-timeout'));
} else {
$spool->recover();
}
}
$sent = $spool->flushQueue($this->getContainer()->get('swiftmailer.transport.real'));
$output->writeln(sprintf('sent %s emails', $sent));