I’m creating a task in a symfony 1.4 project, and I need to update some tables.
I’ve written :
<?php
class dataImportTask extends sfBaseTask
{
public function configure()
{
$this->namespace = 'data';
$this->name = 'import';
$this->addOptions(array(
new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'environment', 'dev'),
));
}
public function execute($arguments = array(), $options = array())
{
$databaseManager = new sfDatabaseManager(sfProjectConfiguration::getApplicationConfiguration('frontend', $options['env'], true));
$connection = $databaseManager->getDatabase()->getConnection();
}
}
(Following the example found on symfony-project.org)
But when I execute the task, symfony says : “Database "default" does not exist.“. Why doesn’t the task uses the dbname defined in databases.yml ?
It’s a common problem when working with task. You have 2 options:
defaultin the database.ymlFor option #2, you have to add an option with the name (the one define in your
database.yml) of your database and then change the way thegetDatabaseworks:In the database.yml:
Based on the doctrine name above, add the option in your task: