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