Getting application / module context from symfony task

I have written a set of reports and I have a special report that creates a CSV file. Serving this file through the browser on demand is not a problem, but I need to be able to collect this CSV file at night and send an email link to download it.

Essentially, I need to be able to replace a specific action with a symfony task running through cron. So how do I get the application / module context from a symfony task? And secondly, how can I call the SwiftMailer library from a symfony task?

I am using symfony v1.4.4 and PHP v.5.2.13.

+3
source share
2 answers

configure() , :

$this->addOptions(array(
  new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED, 'The application name','frontend'),
  new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),
  new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'doctrine'),
));

execute():

sfContext::createInstance($this->configuration);

, Swift:

$this->getMailer()->composeAndSend($sender,$dest, $subject, $mailBody);
+5

, --application --env CLI, taskName::configure()

taskName::execute() :

$context = sfContext::createInstance(ProjectConfiguration::getApplicationConfiguration($options['application'], $options['env']))
0

Source: https://habr.com/ru/post/1748495/


All Articles