A few days ago someone asked on #symfony if it is possible to make symfony load fixtures from different places depending on the environment.
To do this, you have to define your own task. Here’s one I just created. As a bonus, this task also loads sql files from a separate sql directory.
Here’s the task:
<?php/*** This task does almost the same as doctrine:data-load, but it also* loads the sql from the files in the data/sqlextra directory And takes into account the current environment.*** Use instead of doctrine:data-load*/class nnv_load_dataTask extends sfBaseTask{protected function configure(){$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'),// add your own options here));$this->namespace ='data';$this->name ='load-data';$this->briefDescription ='Load fixtures and sql based on environment';$this->detailedDescription =<<<EOFThis [nnv_load_data|INFO] task does almost the same as doctrine:data-load, but it alsoloads the sql from the files in the data/sqlextra/$env directory and loads fixtures from the data/fixtures/$env dir.Use instead of doctrine:data-loadCall it with:[php symfony load_extra_sql|INFO]EOF;}protected function execute($arguments = array(), $options = array()){// initialize the database connection$databaseManager = new sfDatabaseManager($this->configuration);$connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection();Doctrine::loadData(sfConfig::get('sf_root_dir').'/data/fixtures/'. $env);$env = $options['env'];$files = glob(sfConfig::get('sf_root_dir')."/data/sqlextra/$env/*.sql");foreach ($files as $file) {print"Loading". $file ."...";$sql = file_get_contents($file) ;try {$n = $connection->exec($sql);print"ok: $n\n";} catch (Exception $e) {print"Error loading statement: \n$stmt\n:". $e->getMessage();}}}}