Development

/branches/1.2/lib/plugins/sfPropelPlugin/lib/task/sfPropelBuildAllLoadTask.class.php

You must first sign up to be able to contribute.

root/branches/1.2/lib/plugins/sfPropelPlugin/lib/task/sfPropelBuildAllLoadTask.class.php

Revision 12537, 4.2 kB (checked in by fabien, 6 years ago)

[1.2] fixed autoloading in tasks (closes #4675, #4346)

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1 <?php
2
3 /*
4  * This file is part of the symfony package.
5  * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 require_once(dirname(__FILE__).'/sfPropelBaseTask.class.php');
12
13 /**
14  * Generates Propel model, SQL, initializes database, and load data.
15  *
16  * @package    symfony
17  * @subpackage propel
18  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
19  * @version    SVN: $Id$
20  */
21 class sfPropelBuildAllLoadTask extends sfPropelBaseTask
22 {
23   /**
24    * @see sfTask
25    */
26   protected function configure()
27   {
28     $this->addOptions(array(
29       new sfCommandOption('application', null, sfCommandOption::PARAMETER_OPTIONAL, 'The application name', true),
30       new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),
31       new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'propel'),
32       new sfCommandOption('no-confirmation', null, sfCommandOption::PARAMETER_NONE, 'Do not ask for confirmation'),
33       new sfCommandOption('skip-forms', 'F', sfCommandOption::PARAMETER_NONE, 'Skip generating forms'),
34       new sfCommandOption('classes-only', 'C', sfCommandOption::PARAMETER_NONE, 'Do not initialize the database'),
35       new sfCommandOption('phing-arg', null, sfCommandOption::PARAMETER_REQUIRED | sfCommandOption::IS_ARRAY, 'Arbitrary phing argument'),
36       new sfCommandOption('append', null, sfCommandOption::PARAMETER_NONE, 'Don\'t delete current data in the database'),
37       new sfCommandOption('dir', null, sfCommandOption::PARAMETER_REQUIRED | sfCommandOption::IS_ARRAY, 'The directories to look for fixtures'),
38     ));
39
40     $this->aliases = array('propel-build-all-load');
41     $this->namespace = 'propel';
42     $this->name = 'build-all-load';
43     $this->briefDescription = 'Generates Propel model and form classes, SQL, initializes the database, and loads data';
44
45     $this->detailedDescription = <<<EOF
46 The [propel:build-all-load|INFO] task is a shortcut for two other tasks:
47
48   [./symfony propel:build-all-load|INFO]
49
50 The task is equivalent to:
51
52   [./symfony propel:build-all|INFO]
53   [./symfony propel:data-load|INFO]
54
55 See those tasks' help pages for more information.
56
57 To bypass the confirmation, you can pass the [no-confirmation|COMMENT]
58 option:
59
60   [./symfony propel:buil-all-load --no-confirmation|INFO]
61 EOF;
62   }
63
64   /**
65    * @see sfTask
66    */
67   protected function execute($arguments = array(), $options = array())
68   {
69     // load Propel configuration before Phing
70     $databaseManager = new sfDatabaseManager($this->configuration);
71
72     require_once dirname(__FILE__) . '/../addon/sfPropelAutoload.php';
73
74     $buildAll = new sfPropelBuildAllTask($this->dispatcher, $this->formatter);
75     $buildAll->setCommandApplication($this->commandApplication);
76
77     $buildAllOptions = array('--env='.$options['env'], '--connection='.$options['connection']);
78     foreach ($options['phing-arg'] as $arg)
79     {
80       $buildAllOptions[] = '--phing-arg='.escapeshellarg($arg);
81     }
82     if ($options['application'])
83     {
84       $buildAllOptions[] = '--application='.$options['application'];
85     }
86     if ($options['skip-forms'])
87     {
88       $buildAllOptions[] = '--skip-forms';
89     }
90     if ($options['classes-only'])
91     {
92       $buildAllOptions[] = '--classes-only';
93     }
94     if ($options['no-confirmation'])
95     {
96       $buildAllOptions[] = '--no-confirmation';
97     }
98     $ret = $buildAll->run(array(), $buildAllOptions);
99
100     if (0 == $ret)
101     {
102       $loadData = new sfPropelLoadDataTask($this->dispatcher, $this->formatter);
103       $loadData->setCommandApplication($this->commandApplication);
104
105       $dataLoadOptions = array('--env='.$options['env'], '--connection='.$options['connection']);
106       if ($options['application'])
107       {
108         $dataLoadOptions[] = '--application='.$options['application'];
109       }
110       if ($options['dir'])
111       {
112         foreach ($options['dir'] as $dir)
113         {
114           $dataLoadOptions[] = '--dir='.$dir;
115         }
116       }
117       if ($options['append'])
118       {
119         $dataLoadOptions[] = '--append';
120       }
121
122       $loadData->run(array(), $dataLoadOptions);
123     }
124
125     $this->cleanup();
126
127     return $ret;
128   }
129 }
130
Note: See TracBrowser for help on using the browser.