Development

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

You must first sign up to be able to contribute.

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

Revision 20867, 4.8 kB (checked in by Kris.Wallsmith, 5 years ago)

[1.3] fixed refreshing of autoloader from inside generator tasks, removed unnecessary use of sfSimpleAutoload

  • 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     $buildModel->setConfiguration($this->configuration);
83     $ret = $buildModel->run(array(), array(
84       'phing-arg' => $options['phing-arg'],
85     ));
86
87     if ($ret)
88     {
89       return $ret;
90     }
91
92     if (!$options['skip-forms'])
93     {
94       $this->logBlock(array(
95         'Phing was run before and used many custom classes that might conflict with',
96         'your model classes. In case of errors try running "propel:build-forms" and',
97         '"propel:build-filters" alone. This is due to a PHP limitation that cannot be',
98         'fixed in symfony.',
99       ), 'INFO');
100
101       $buildForms = new sfPropelBuildFormsTask($this->dispatcher, $this->formatter);
102       $buildForms->setCommandApplication($this->commandApplication);
103       $buildForms->setConfiguration($this->configuration);
104       $ret = $buildForms->run();
105
106       if ($ret)
107       {
108         return $ret;
109       }
110
111       $buildFilters = new sfPropelBuildFiltersTask($this->dispatcher, $this->formatter);
112       $buildFilters->setCommandApplication($this->commandApplication);
113       $buildFilters->setConfiguration($this->configuration);
114       $ret = $buildFilters->run();
115
116       if ($ret)
117       {
118         return $ret;
119       }
120     }
121
122     if (!$options['classes-only'])
123     {
124       $buildSql = new sfPropelBuildSqlTask($this->dispatcher, $this->formatter);
125       $buildSql->setCommandApplication($this->commandApplication);
126       $buildSql->setConfiguration($this->configuration);
127       $ret = $buildSql->run(array(), array(
128         'phing-arg' => $options['phing-arg'],
129       ));
130
131       if ($ret)
132       {
133         return $ret;
134       }
135
136       $insertSql = new sfPropelInsertSqlTask($this->dispatcher, $this->formatter);
137       $insertSql->setCommandApplication($this->commandApplication);
138       $insertSql->setConfiguration($this->configuration);
139       $ret = $insertSql->run(array(), array(
140         'phing-arg'       => $options['phing-arg'],
141         'connection'      => $options['connection'],
142         'no-confirmation' => $options['no-confirmation'],
143       ));
144
145       if ($ret)
146       {
147         return $ret;
148       }
149     }
150
151     $this->reloadAutoload();
152   }
153 }
154
Note: See TracBrowser for help on using the browser.