| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
class sfProjectSendEmailsTask extends sfBaseTask |
|---|
| 20 |
{ |
|---|
| 21 |
|
|---|
| 22 |
* @see sfTask |
|---|
| 23 |
*/ |
|---|
| 24 |
protected function configure() |
|---|
| 25 |
{ |
|---|
| 26 |
$this->addOptions(array( |
|---|
| 27 |
new sfCommandOption('application', null, sfCommandOption::PARAMETER_OPTIONAL, 'The application name', true), |
|---|
| 28 |
new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'), |
|---|
| 29 |
new sfCommandOption('message-limit', null, sfCommandOption::PARAMETER_OPTIONAL, 'The maximum number of messages to send', 0), |
|---|
| 30 |
new sfCommandOption('time-limit', null, sfCommandOption::PARAMETER_OPTIONAL, 'The time limit for sending messages (in seconds)', 0), |
|---|
| 31 |
)); |
|---|
| 32 |
|
|---|
| 33 |
$this->namespace = 'project'; |
|---|
| 34 |
$this->name = 'send-emails'; |
|---|
| 35 |
|
|---|
| 36 |
$this->briefDescription = 'Sends emails stored in a queue'; |
|---|
| 37 |
|
|---|
| 38 |
$this->detailedDescription = <<<EOF |
|---|
| 39 |
The [project:send-emails|INFO] sends emails stored in a queue: |
|---|
| 40 |
|
|---|
| 41 |
[php symfony project:send-emails|INFO] |
|---|
| 42 |
|
|---|
| 43 |
You can limit the number of messages to send: |
|---|
| 44 |
|
|---|
| 45 |
[php symfony project:send-emails --message-limit=10|INFO] |
|---|
| 46 |
|
|---|
| 47 |
Or limit to time (in seconds): |
|---|
| 48 |
|
|---|
| 49 |
[php symfony project:send-emails --time-limit=10|INFO] |
|---|
| 50 |
EOF; |
|---|
| 51 |
} |
|---|
| 52 |
|
|---|
| 53 |
protected function execute($arguments = array(), $options = array()) |
|---|
| 54 |
{ |
|---|
| 55 |
$databaseManager = new sfDatabaseManager($this->configuration); |
|---|
| 56 |
|
|---|
| 57 |
$spool = $this->getMailer()->getSpool(); |
|---|
| 58 |
$spool->setMessageLimit($options['message-limit']); |
|---|
| 59 |
$spool->setTimeLimit($options['time-limit']); |
|---|
| 60 |
|
|---|
| 61 |
$sent = $this->getMailer()->flushQueue(); |
|---|
| 62 |
|
|---|
| 63 |
$this->logSection('project', sprintf('sent %s emails', $sent)); |
|---|
| 64 |
} |
|---|
| 65 |
} |
|---|
| 66 |
|
|---|