Code snippets for symfony 1.x

Navigation

Refine Tags

Snippets tagged "ruckusing"

Use databases.yml in Ruckusing Migrations

Replace (or link) Ruckusing's database.inc.php with this code. You'll be able to use symfony's environment names in Ruckusing commands.

Example: php lib/vendor/ruckusing/main.php db:migrate ENV=dev

<?php
$configFile = dirname(__FILE__)."/../../../../config/databases.yml";
include(dirname(__FILE__)."/../../symfony/lib/yaml/sfYaml.class.php");
$connections = sfYaml::Load($configFile);
 
foreach($connections as $con => $val)
{
  if($con == 'all') continue;
  $connection_name = $con;
  $con = array();
  $params = array_pop($val);
  $params = $params['param'];
 
  preg_match("/^(.*)\:/", $params['dsn'], $match);
  $con['type'] = $match[1];
 
  preg_match("/dbname=(.*);/", $params['dsn'], $match);
  $con['database'] = $match[1];
 
  preg_match("/host=(.*);?/", $params['dsn'], $match);
  $con['host'] = $match[1];
 
  if(preg_match("/port=(.*);?/", $params['dsn'], $match))
  {
    $con['port'] = $match[1];
  }
  elseif($con['type'] == 'mysql')
  {
    $con['port'] = 3306;
  }
 
  $con['user'] = $params['username'];
  $con['password'] = $params['password'];
 
  $ruckusing_db_config[$connection_name] = $con;
}
 
// dev and development means the same thing in the two config files
$ruckusing_db_config['development'] = $ruckusing_db_config['dev'];
?>
 
by karoly sz on 2009-10-18, tagged migration  ruckusing