Development

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

You must first sign up to be able to contribute.

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

Revision 13645, 4.7 kB (checked in by Kris.Wallsmith, 6 years ago)

[1.2] fixed formatting of phing notice

  • 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 and initializes the database.
15  *
16  * @package    symfony
17  * @subpackage propel
18  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
19  * @version    SVN: $Id$
20  */
21 class sfPropelBuildAllTask 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     ));
37
38     $this->aliases = array('propel-build-all');
39     $this->namespace = 'propel';
40     $this->name = 'build-all';
41     $this->briefDescription = 'Generates Propel model and form classes, SQL and initializes the database';
42
43     $this->detailedDescription = <<<EOF
44 The [propel:build-all|INFO] task is a shortcut for five other tasks:
45
46   [./symfony propel:build-all|INFO]
47
48 The task is equivalent to:
49
50   [./symfony propel:build-model|INFO]
51   [./symfony propel:build-forms|INFO]
52   [./symfony propel:build-filters|INFO]
53   [./symfony propel:build-sql|INFO]
54   [./symfony propel:insert-sql|INFO]
55
56 See those tasks' help pages for more information.
57
58 To bypass confirmation prompts, you can pass the [no-confirmation|COMMENT] option:
59
60   [./symfony propel:buil-all --no-confirmation|INFO]
61
62 To build all classes but skip initializing the database, use the [classes-only|COMMENT]
63 option:
64
65   [./symfony propel:build-all --classes-only|INFO]
66 EOF;
67   }
68
69   /**
70    * @see sfTask
71    */
72   protected function execute($arguments = array(), $options = array())
73   {
74     $basePhingOptions = array();
75     foreach ($options['phing-arg'] as $arg)
76     {
77       $basePhingOptions[] = '--phing-arg='.escapeshellarg($arg);
78     }
79
80     $buildModel = new sfPropelBuildModelTask($this->dispatcher, $this->formatter);
81     $buildModel->setCommandApplication($this->commandApplication);
82     $ret = $buildModel->run(array(), $basePhingOptions);
83
84     if ($ret)
85     {
86       return $ret;
87     }
88
89     if (!$options['skip-forms'])
90     {
91       $this->logBlock(array(
92         'Phing was run before and used many custom classes that might conflict with',
93         'your model classes. In case of errors try running "propel:build-forms" and',
94         '"propel:build-filters" alone. This is due to a PHP limitation that cannot be',
95         'fixed in symfony.',
96       ), 'INFO');
97
98       $buildForms = new sfPropelBuildFormsTask($this->dispatcher, $this->formatter);
99       $buildForms->setCommandApplication($this->commandApplication);
100       $ret = $buildForms->run();
101
102       if ($ret)
103       {
104         return $ret;
105       }
106
107       $buildFilters = new sfPropelBuildFiltersTask($this->dispatcher, $this->formatter);
108       $buildFilters->setCommandApplication($this->commandApplication);
109       $ret = $buildFilters->run();
110
111       if ($ret)
112       {
113         return $ret;
114       }
115     }
116
117     if (!$options['classes-only'])
118     {
119       $buildSql = new sfPropelBuildSqlTask($this->dispatcher, $this->formatter);
120       $buildSql->setCommandApplication($this->commandApplication);
121       $ret = $buildSql->run(array(), $basePhingOptions);
122
123       if ($ret)
124       {
125         return $ret;
126       }
127
128       $insertSql = new sfPropelInsertSqlTask($this->dispatcher, $this->formatter);
129       $insertSql->setCommandApplication($this->commandApplication);
130
131       $insertSqlOptions = array_merge($basePhingOptions, array('--env='.$options['env'], '--connection='.$options['connection']));
132       if ($options['application'])
133       {
134         $insertSqlOptions[] = '--application='.$options['application'];
135       }
136       if ($options['no-confirmation'])
137       {
138         $insertSqlOptions[] = '--no-confirmation';
139       }
140
141       $ret = $insertSql->run(array(), $insertSqlOptions);
142
143       if ($ret)
144       {
145         return $ret;
146       }
147     }
148   }
149 }
150
Note: See TracBrowser for help on using the browser.