0

I created a task to automate emailing a report in Symfony 1.4. Both this task and a related module for viewing in the web share a custom PHP class file. The task is able to pull in the data correctly, but I have not been able to get it to send out the email. I attempted to follow the official Symfony 1.4 documentation as well as a number of examples from a Google search, but none are solving my problem. The terminal isn't displaying any error either.

My Code:

<?php

require_once sfConfig::get('sf_lib_dir').'/vendor/sesame/reports/reports.class.php';
//use reports;

class reportsTask extends sfBaseTask
{
  protected function configure()
  {
    // // add your own arguments here
    // $this->addArguments(array(
    //   new sfCommandArgument('my_arg', sfCommandArgument::REQUIRED, 'My argument'),
    // ));

    $this->addOptions(array(
      new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED, 'The application name'),
      new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),
      new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'doctrine'),
      new sfCommandOption('type', null, sfCommandOption::PARAMETER_OPTIONAL, 'The output type of the report', 'email')
      // add your own options here
    ));

    $this->namespace        = '';
    $this->name             = 'reports';
    $this->briefDescription = '';
    $this->detailedDescription = <<<EOF
The [reports|INFO] task does things.
Call it with:

  [php symfony reports|INFO]
EOF;
  }

  protected function execute($arguments = array(), $options = array())
  {
    $databaseManager = new sfDatabaseManager($this->configuration);
    $databaseManager->loadConfiguration();
    $reports = new reports();
    $output = $reports->buildReport($options['type']);
    switch($options['type']){
        case 'csv':
            echo $output;
            break;
        case 'email':
            $message = $this->getMailer()->compose($output['from'], $output['to'], $output['subject']);
            $message->setBody($output['body']['content'], $output['body']['type']);
            $message->attach(Swift_Attachment::newInstance($output['attachment']['content'], $output['attachment']['name'], $output['attachment']['type']));
            $this->getMailer()->sendNextImmediately()->send($message) or die('email failed to deliver');
            $output = array('status'=>'success', 'to'=>$output['to']);
        default:
            $this->logSection('results', json_encode($output));
    }
  }
}

The terminal command being attempted from the project root:

php symfony reports

Any answers leading to the right path would be most helpful. Please keep in mind that I need to stay with version 1.4. The server is capable of sending off emails and my module version does just that when invoked by a URL. I need it to run on the command line though so I can set up a cron.

jperry
  • 1
  • 1

0 Answers0