The cause of my actual problem
After some deep debugging using a clean task, I finally found my culprit. Symfony 1.4 seems to run the configure method for each task in the task directory before executing the task.
Unfortunately, some uninformed prankster (former colleague * ) included some initialization of the hard coded context in one of these methods, for example:
// inside a task protected function configure() { // context was initialized $configuration = ProjectConfiguration::getApplicationConfiguration('app_name', 'prod', true); $context = sfContext::createInstance($configuration); // so the following was available in the configure method $save_path = sfConfig::get('sf_app_config_dir'); // rest of configure method implementation // ... }
This got the database settings for all cronjobs in all other environments, except for the production environment (fortunately).
I managed to get around this by doing something like this:
protected function configure() { $configuration = ProjectConfiguration::getApplicationConfiguration('app_name', 'prod', true); // removed the context creation $configuration->activate(); // this makes the sfConfig::get() work $save_path = sfConfig::get('sf_app_config_dir'); // rest of configure method implementation // ... }
Answer my question
I also found that when it comes to controlling which database connection Doctrine_Query::create() is using, you can have some control using something like this for a higher level function:
// for making sure the 'auth' database settings are used as a default Doctrine_Manager::getInstance()->setCurrentConnection('auth');
However, this has no authority over the fact that the "environment partition" is used to select the correct / dsn configuration for the database. This is done using the following:
// somewhere in the execute method $env = 'dev'; // the environment section name; $configuration = ProjectConfiguration::getApplicationConfiguration('app_name', $env, true); $context = sfContext::createInstance($configuration);
As also correctly outlined in the answers by Alex Blex and Marek . Using the task option to support multiple environments, as they suggest, makes sense.
*: My former colleague whom I can hardly go crazy because of the uniqueness and counteraction to the intuitive nature of this problem;)