Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
 
3
/*
4
 * This file is part of the symfony package.
5
 * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
 
11
/**
12
 * Send emails stored in a queue.
13
 *
14
 * @package    symfony
15
 * @subpackage task
16
 * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17
 * @version    SVN: $Id: sfProjectSendEmailsTask.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
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
}