Development

/branches/1.2/lib/plugins/sfDoctrinePlugin/lib/task/sfDoctrineBaseTask.class.php

You must first sign up to be able to contribute.

root/branches/1.2/lib/plugins/sfDoctrinePlugin/lib/task/sfDoctrineBaseTask.class.php

Revision 15865, 3.2 kB (checked in by Jonathan.Wage, 5 years ago)

[1.2, 1.3] Fixes issue with loading data fixtures from plugins that use setPluginPath()

  • Property svn:keywords set to Id Date Author Revision HeadURL
Line 
1 <?php
2
3 /*
4  * This file is part of the symfony package.
5  * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
6  * (c) Jonathan H. Wage <jonwage@gmail.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 /**
13  * Base class for all symfony Doctrine tasks.
14  *
15  * @package    symfony
16  * @subpackage doctrine
17  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
18  * @author     Jonathan H. Wage <jonwage@gmail.com>
19  * @version    SVN: $Id$
20  */
21 abstract class sfDoctrineBaseTask extends sfBaseTask
22 {
23   static protected $done = false;
24
25   public function initialize(sfEventDispatcher $dispatcher, sfFormatter $formatter)
26   {
27     parent::initialize($dispatcher, $formatter);
28     self::$done = true;
29   }
30
31   protected function createConfiguration($application, $env)
32   {
33     $configuration = parent::createConfiguration($application, $env);
34
35     $autoloader = sfSimpleAutoload::getInstance();
36     $config = new sfAutoloadConfigHandler();
37     $mapping = $config->evaluate($configuration->getConfigPaths('config/autoload.yml'));
38     foreach ($mapping as $class => $file)
39     {
40       $autoloader->setClassPath($class, $file);
41     }
42     $autoloader->register();
43
44     return $configuration;
45   }
46   /**
47    * Get array of configuration variables for the Doctrine cli
48    *
49    * @return array $config
50    */
51   public function getCliConfig()
52   {
53     $fixtures = array();
54     $fixtures[] = sfConfig::get('sf_root_dir').'/data/fixtures';
55     $pluginPaths = $this->configuration->getPluginPaths();
56     foreach ($pluginPaths as $pluginPath)
57     {
58       if (is_dir($dir = $pluginPath.'/data/fixtures'))
59       {
60         $fixtures[] = $dir;
61       }
62     }
63     $models = sfConfig::get('sf_lib_dir') . DIRECTORY_SEPARATOR . 'model' . DIRECTORY_SEPARATOR . 'doctrine';
64     $migrations = sfConfig::get('sf_lib_dir') . DIRECTORY_SEPARATOR . 'migration' . DIRECTORY_SEPARATOR . 'doctrine';
65     $sql = sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR . 'sql';
66     $yaml = sfConfig::get('sf_config_dir') . DIRECTORY_SEPARATOR . 'doctrine';
67
68     $config = array('data_fixtures_path'  =>  $fixtures,
69                     'models_path'         =>  $models,
70                     'migrations_path'     =>  $migrations,
71                     'sql_path'            =>  $sql,
72                     'yaml_schema_path'    =>  $yaml);
73
74     foreach ($config as $dir)
75     {
76       $dirs = (array) $dir;
77       foreach ($dirs as $dir)
78       {
79         Doctrine_Lib::makeDirectories($dir);
80       }
81     }
82
83     return $config;
84   }
85
86   /**
87    * Call a command from the Doctrine CLI
88    *
89    * @param string $task Name of the Doctrine task to call
90    * @param string $args Arguments for the task
91    * @return void
92    */
93   public function callDoctrineCli($task, $args = array())
94   {
95     $config = $this->getCliConfig();
96
97     $arguments = array('./symfony', $task);
98
99     foreach ($args as $key => $arg)
100     {
101       if (isset($config[$key]))
102       {
103         $config[$key] = $arg;
104       } else {
105         $arguments[] = $arg;
106       }
107     }
108
109     $cli = new sfDoctrineCli($config);
110     $cli->setDispatcher($this->dispatcher);
111     $cli->setFormatter($this->formatter);
112     $cli->run($arguments);
113   }
114 }
Note: See TracBrowser for help on using the browser.