* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ /** * Generates a new application. * * @package symfony * @subpackage task * @author Fabien Potencier * @version SVN: $Id: sfConfigureDatabaseTask.class.php 20304 2009-07-19 11:11:16Z fabien $ */ class sfConfigureDatabaseTask extends sfBaseTask { /** * @see sfTask */ protected function configure() { $this->addArguments(array( new sfCommandArgument('dsn', sfCommandArgument::REQUIRED, 'The database dsn'), new sfCommandArgument('username', sfCommandArgument::OPTIONAL, 'The database username', 'root'), new sfCommandArgument('password', sfCommandArgument::OPTIONAL, 'The database password'), )); $this->addOptions(array( new sfCommandOption('env', null, sfCommandOption::PARAMETER_OPTIONAL, 'The environment', 'all'), new sfCommandOption('name', null, sfCommandOption::PARAMETER_OPTIONAL, 'The connection name', 'propel'), new sfCommandOption('class', null, sfCommandOption::PARAMETER_OPTIONAL, 'The database class name', 'sfPropelDatabase'), new sfCommandOption('app', null, sfCommandOption::PARAMETER_OPTIONAL, 'The application name', null), )); $this->namespace = 'configure'; $this->name = 'database'; $this->briefDescription = 'Configure database DSN'; $this->detailedDescription = << $options['class'], 'param' => array_merge(isset($config[$options['env']][$options['name']]['param']) ? $config[$options['env']][$options['name']]['param'] : array(), array('dsn' => $arguments['dsn'], 'username' => $arguments['username'], 'password' => $arguments['password'])), ); file_put_contents($file, sfYaml::dump($config, 4)); // update propel.ini if ( is_null($options['app']) && false !== strpos($options['class'], 'Propel') && 'all' == $options['env'] ) { $propelini = sfConfig::get('sf_config_dir').'/propel.ini'; if (file_exists($propelini)) { $content = file_get_contents($propelini); if (preg_match('/^(.+?):/', $arguments['dsn'], $match)) { $content = preg_replace('/^propel\.database(\s*)=(\s*)(.+?)$/m', 'propel.database$1=${2}'.$match[1], $content); $content = preg_replace('/^propel\.database.driver(\s*)=(\s*)(.+?)$/m', 'propel.database.driver$1=${2}'.$match[1], $content); $content = preg_replace('/^propel\.database\.createUrl(\s*)=(\s*)(.+?)$/m', 'propel.database.createUrl$1=${2}'.$arguments['dsn'], $content); $content = preg_replace('/^propel\.database\.url(\s*)=(\s*)(.+?)$/m', 'propel.database.url$1=${2}'.$arguments['dsn'], $content); $content = preg_replace('/^propel\.database\.user(\s*)=(\s*)(.+?)$/m', 'propel.database.user$1=${2}'.$arguments['username'], $content); $content = preg_replace('/^propel\.database\.password(\s*)=(\s*)(.+?)$/m', 'propel.database.password$1=${2}'.$arguments['password'], $content); file_put_contents($propelini, $content); } } } } }