views:

40

answers:

2

I am running Symfony 1.3.2 on Ubuntu. I need to write a batch script that can:

  • Access the database using the ORM
  • Send email(s)

IIRC, this was in a previous cookback, but I thing that was for an earlier version of Symfony (the API may have changed since).

Does anyone know how I may access the database via the ORM layer in a batch script and also how to send out email(s) in a batch script?

+1  A: 

Yep, put this at the top of your script:

require_once('/... ABSOLUTE_PATH...../config/ProjectConfiguration.class.php');
$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'prod', false);
sfContext::createInstance($configuration);

... and change the ABSOLUTE_PATH to the absolute path to the ProjectConguration class. Works for a batch script and allows use of ORM. Haven't tested with the standard Symfony SwiftMailer but assume would be fine.

The settings "frontend" and "prod" and "false" and app/environment-specific. You can read more about them in the Symfony API documentation.

Tom
@tom: +1 for the code snippet
morpheous
+3  A: 

See also Sending email from a task in the "More with symfony" book.

If you get your task working, you can run it from cron or the command line.

Nathan
@nathan: +1 for the links
morpheous
+1 for using tasks :-)
richsage