Development

Changeset 5383

You must first sign up to be able to contribute.

Changeset 5383

Show
Ignore:
Timestamp:
10/05/07 20:53:41 (1 year ago)
Author:
Jonathan.Wage
Message:

Getting all the pake tasks working correctly.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfDoctrinePlugin/trunk/lib/sfDoctrineSchemasConfigHandler.class.php

    r5376 r5383  
    4242            if (empty($components)) { 
    4343                $schema = explode('/', $schemaFile); 
     44                 
     45                if (!isset($schema[1])) { 
     46                  continue; 
     47                } 
     48                 
    4449                $pluginName = $schema[0]; 
    4550                $schema = $schema[1]; 
  • plugins/sfDoctrinePlugin/trunk/lib/tasks/sfDoctrineBaseTask.class.php

    r5374 r5383  
    1919abstract class sfDoctrineBaseTask extends sfBaseTask 
    2020{ 
    21   public function loadDoctrine() 
     21  public function loadModels() 
    2222  { 
    23     require_once(dirname(dirname(__FILE__)).'/doctrine/Doctrine.php'); 
    24      
    2523    $directories = array(); 
    2624    $directories[] = sfConfig::get('sf_model_lib_dir') . DIRECTORY_SEPARATOR . 'doctrine'; 
     
    4038    $models = Doctrine::loadModels($directories); 
    4139  } 
     40   
     41  public function loadConnections() 
     42  { 
     43    $doctrineConfigPath = sfConfig::get('sf_plugins_dir').'/sfDoctrinePlugin/config/doctrine.yml'; 
     44     
     45    $config = new sfDoctrineConfigHandler(); 
     46    $php = str_replace('<?php', '', $config->execute(array($doctrineConfigPath))); 
     47     
     48    eval($php); 
     49     
     50    $databases = sfYaml::load(sfConfig::get('sf_config_dir').'/databases.yml'); 
     51    $databases = $databases['all']; 
     52     
     53    foreach ($databases as $name => $database) 
     54    { 
     55      $info = Doctrine_Manager::getInstance()->parseDsn($database['param']['dsn']); 
     56       
     57      $dsn = $info['dsn']; 
     58      $user = $info['user']; 
     59      $password = $info['pass']; 
     60       
     61      $connection = Doctrine_Manager::getInstance()->openConnection(new PDO($dsn, $user, $password), $name); 
     62       
     63      // Load attributes to connection 
     64      foreach($default_attributes as $k => $v) 
     65      { 
     66        $connection->setAttribute(constant('Doctrine::'.$k), $v); 
     67      } 
     68    } 
     69     
     70    // Apply connection component binding 
     71    $schemasPath = sfConfig::get('sf_config_dir').'/schemas.yml'; 
     72     
     73    if (file_exists($schemasPath)) { 
     74      $schemas = new sfDoctrineSchemasConfigHandler(); 
     75      $php = str_replace('<?php', '', $schemas->execute(array($schemasPath))); 
     76       
     77      eval($php); 
     78    } 
     79  } 
    4280} 
  • plugins/sfDoctrinePlugin/trunk/lib/tasks/sfDoctrineBuildAllTask.class.php

    r5370 r5383  
    5252    $buildModel->run(); 
    5353 
    54     $buildSql = new sfDoctrineBuildSqlTask($this->dispatcher, $this->formatter); 
    55     $buildSql->run(); 
    56  
    5754    $insertSql = new sfDoctrineInsertSqlTask($this->dispatcher, $this->formatter); 
    5855    $insertSql->run(); 
  • plugins/sfDoctrinePlugin/trunk/lib/tasks/sfDoctrineBuildDbTask.class.php

    r5370 r5383  
    2323   */ 
    2424  protected function configure() 
    25   {     
     25  { 
    2626    $this->aliases = array('doctrine-build-db'); 
    2727    $this->namespace = 'doctrine'; 
     
    4545  protected function execute($arguments = array(), $options = array()) 
    4646  { 
    47  
     47    $databases = sfYaml::load(sfConfig::get('sf_config_dir').'/databases.yml'); 
     48    $databases = $databases['all']; 
     49     
     50    foreach ($databases as $name => $database) 
     51    { 
     52      $dsn = $database['param']['dsn']; 
     53      $info = Doctrine_Manager::getInstance()->parseDsn($dsn); 
     54       
     55      $dsn = $info['scheme'].':host='.$info['host']; 
     56      $user = $info['user']; 
     57      $password = $info['pass']; 
     58       
     59      $connection = Doctrine_Manager::getInstance()->openConnection(new PDO($dsn, $user, $password), $name); 
     60       
     61      try { 
     62        $connection->export->createDatabase($info['database']); 
     63      } catch(Exception $e) { 
     64         
     65      } 
     66    } 
    4867  } 
    4968} 
  • plugins/sfDoctrinePlugin/trunk/lib/tasks/sfDoctrineBuildSchemaTask.class.php

    r5370 r5383  
    2424  protected function configure() 
    2525  { 
    26     $this->addArguments(array( 
    27       new sfCommandArgument('application', sfCommandArgument::REQUIRED, 'The application name') 
    28     )); 
    29  
    30     $this->addOptions(array( 
    31       new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environement', 'dev'), 
    32       new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'doctrine'), 
    33     )); 
    34      
    3526    $this->aliases = array('doctrine-build-schema'); 
    3627    $this->namespace = 'doctrine'; 
     
    5243  protected function execute($arguments = array(), $options = array()) 
    5344  { 
    54     $this->bootstrapSymfony($arguments['application'], $options['env'], true); 
     45    $this->loadConnections(); 
    5546     
    5647    $schema = sfConfig::get('sf_root_dir') . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'doctrine' . DIRECTORY_SEPARATOR . 'schema.yml'; 
  • plugins/sfDoctrinePlugin/trunk/lib/tasks/sfDoctrineBuildSqlTask.class.php

    r5370 r5383  
    2323   */ 
    2424  protected function configure() 
    25   { 
    26     $this->addArguments(array( 
    27       new sfCommandArgument('application', sfCommandArgument::REQUIRED, 'The application name') 
    28     )); 
    29  
    30     $this->addOptions(array( 
    31       new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environement', 'dev'), 
    32       new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'doctrine'), 
    33     )); 
    34      
     25  {     
    3526    $this->aliases = array('doctrine-build-sql'); 
    3627    $this->namespace = 'doctrine'; 
     
    5445  protected function execute($arguments = array(), $options = array()) 
    5546  { 
    56     $this->bootstrapSymfony($arguments['application'], $options['env'], true); 
     47    $this->loadConnections(); 
    5748     
    5849    $sqlPath = sfConfig::get('sf_root_dir').'/data/sql'; 
    5950     
    60     $sql = Doctrine::exportSql(sfConfig::get('sf_root_dir').'/lib/model/doctrine'); 
    61      
    62     file_put_contents($sqlPath.'/doctrine-schema.sql', implode("\n", $sql)); 
     51    $directories = array(); 
     52    $directories[] = sfConfig::get('sf_root_dir').'/lib/model/doctrine'; 
    6353     
    6454    // Build sql for all of the plugins 
     
    6757    foreach ($plugins as $plugin) 
    6858    { 
    69       $name = basename($plugin)
     59      $pluginModelPath = sfConfig::get('sf_plugins_dir').'/'.basename($plugin).'/lib/model/doctrine'
    7060       
    71       $pluginModels = sfConfig::get('sf_plugins_dir').'/'.$name.'/lib/model/doctrine'; 
    72        
    73       if (file_exists($pluginModels)) 
    74       { 
    75         $sql = Doctrine::exportSql($pluginModels); 
    76          
    77         file_put_contents($sqlPath.'/doctrine-'.$name.'-schema.sql', implode("\n", $sql)); 
     61      if (file_exists($pluginModelPath)) { 
     62        $directories[] = $pluginModelPath; 
    7863      } 
    7964    } 
     65     
     66    $sql = Doctrine::exportSql($directories); 
     67     
     68    file_put_contents($sqlPath.'/doctrine-schema.sql', implode("\n", $sql)); 
    8069  } 
    8170} 
  • plugins/sfDoctrinePlugin/trunk/lib/tasks/sfDoctrineDataDumpTask.class.php

    r5370 r5383  
    6565    $this->bootstrapSymfony($arguments['application'], $options['env'], true); 
    6666 
    67     $this->loadDoctrine(); 
    68      
    69     $databaseManager = new sfDatabaseManager(); 
    70  
    7167    if (!sfToolkit::isPathAbsolute($filename)) 
    7268    { 
  • plugins/sfDoctrinePlugin/trunk/lib/tasks/sfDoctrineDataLoadTask.class.php

    r5370 r5383  
    6565    $this->bootstrapSymfony($arguments['application'], $options['env'], true); 
    6666     
    67     $this->loadDoctrine(); 
    68      
    6967    sfSimpleAutoload::getInstance()->unregister(); 
    7068    sfSimpleAutoload::getInstance()->register(); 
  • plugins/sfDoctrinePlugin/trunk/lib/tasks/sfDoctrineGenerateCrudTask.class.php

    r5374 r5383  
    6363    $this->bootstrapSymfony($arguments['application'], $options['env'], true); 
    6464     
    65     $this->loadDoctrine(); 
    66      
    6765    // generate module 
    6866    $tmpDir = sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR.'tmp'.DIRECTORY_SEPARATOR.md5(uniqid(rand(), true)); 
  • plugins/sfDoctrinePlugin/trunk/lib/tasks/sfDoctrineInsertSqlTask.class.php

    r5370 r5383  
    2424  protected function configure() 
    2525  { 
    26     $this->addArguments(array( 
    27       new sfCommandArgument('application', sfCommandArgument::REQUIRED, 'The application name') 
    28     )); 
    29  
    30     $this->addOptions(array( 
    31       new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environement', 'dev'), 
    32       new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'doctrine'), 
    33     )); 
    34      
    3526    $this->aliases = array('doctrine-insert-sql'); 
    3627    $this->namespace = 'doctrine'; 
     
    5344  protected function execute($arguments = array(), $options = array()) 
    5445  { 
    55     $this->bootstrapSymfony($arguments['application'], $options['env'], true); 
     46    $this->loadConnections(); 
    5647     
    5748    Doctrine::exportSchema(sfConfig::get('sf_root_dir').'/lib/model/doctrine');