| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
require_once(dirname(__FILE__).'/sfDoctrineBaseTask.class.php'); |
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
class sfDoctrineBuildAllLoadTask extends sfDoctrineBaseTask |
|---|
| 24 |
{ |
|---|
| 25 |
|
|---|
| 26 |
* @see sfTask |
|---|
| 27 |
*/ |
|---|
| 28 |
protected function configure() |
|---|
| 29 |
{ |
|---|
| 30 |
$this->addOptions(array( |
|---|
| 31 |
new sfCommandOption('application', null, sfCommandOption::PARAMETER_OPTIONAL, 'The application name', true), |
|---|
| 32 |
new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'), |
|---|
| 33 |
new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'doctrine'), |
|---|
| 34 |
new sfCommandOption('no-confirmation', null, sfCommandOption::PARAMETER_NONE, 'Do not ask for confirmation'), |
|---|
| 35 |
new sfCommandOption('skip-forms', 'F', sfCommandOption::PARAMETER_NONE, 'Skip generating forms'), |
|---|
| 36 |
new sfCommandOption('dir', null, sfCommandOption::PARAMETER_REQUIRED | sfCommandOption::IS_ARRAY, 'The directories to look for fixtures'), |
|---|
| 37 |
)); |
|---|
| 38 |
|
|---|
| 39 |
$this->aliases = array('doctrine-build-all-load'); |
|---|
| 40 |
$this->namespace = 'doctrine'; |
|---|
| 41 |
$this->name = 'build-all-load'; |
|---|
| 42 |
$this->briefDescription = 'Generates Doctrine model, SQL, initializes database, and loads fixtures data'; |
|---|
| 43 |
|
|---|
| 44 |
$this->detailedDescription = <<<EOF |
|---|
| 45 |
The [doctrine:build-all-load|INFO] task is a shortcut for two other tasks: |
|---|
| 46 |
|
|---|
| 47 |
[./symfony doctrine:build-all-load|INFO] |
|---|
| 48 |
|
|---|
| 49 |
The task is equivalent to: |
|---|
| 50 |
|
|---|
| 51 |
[./symfony doctrine:build-all|INFO] |
|---|
| 52 |
[./symfony doctrine:data-load|INFO] |
|---|
| 53 |
|
|---|
| 54 |
The task takes an application argument because of the [doctrine:data-load|COMMENT] |
|---|
| 55 |
task. See [doctrine:data-load|COMMENT] help page for more information. |
|---|
| 56 |
|
|---|
| 57 |
To bypass the confirmation, you can pass the [no-confirmation|COMMENT] |
|---|
| 58 |
option: |
|---|
| 59 |
|
|---|
| 60 |
[./symfony doctrine:build-all-load --no-confirmation|INFO] |
|---|
| 61 |
EOF; |
|---|
| 62 |
} |
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
* @see sfTask |
|---|
| 66 |
*/ |
|---|
| 67 |
protected function execute($arguments = array(), $options = array()) |
|---|
| 68 |
{ |
|---|
| 69 |
$databaseManager = new sfDatabaseManager($this->configuration); |
|---|
| 70 |
|
|---|
| 71 |
$buildAll = new sfDoctrineBuildAllTask($this->dispatcher, $this->formatter); |
|---|
| 72 |
$buildAll->setCommandApplication($this->commandApplication); |
|---|
| 73 |
|
|---|
| 74 |
$buildAllOptions = array(); |
|---|
| 75 |
if ($options['skip-forms']) |
|---|
| 76 |
{ |
|---|
| 77 |
$buildAllOptions[] = '--skip-forms'; |
|---|
| 78 |
} |
|---|
| 79 |
if ($options['no-confirmation']) |
|---|
| 80 |
{ |
|---|
| 81 |
$buildAllOptions[] = '--no-confirmation'; |
|---|
| 82 |
} |
|---|
| 83 |
if (isset($options['application']) && $options['application']) |
|---|
| 84 |
{ |
|---|
| 85 |
$buildAllOptions[] = '--application=' . $options['application']; |
|---|
| 86 |
} |
|---|
| 87 |
$ret = $buildAll->run(array(), $buildAllOptions); |
|---|
| 88 |
|
|---|
| 89 |
if (0 == $ret) |
|---|
| 90 |
{ |
|---|
| 91 |
$loadData = new sfDoctrineLoadDataTask($this->dispatcher, $this->formatter); |
|---|
| 92 |
$loadData->setCommandApplication($this->commandApplication); |
|---|
| 93 |
|
|---|
| 94 |
$loadDataOptions = array('--env='.$options['env'], '--connection='.$options['connection']); |
|---|
| 95 |
if (isset($options['application'])) |
|---|
| 96 |
{ |
|---|
| 97 |
$loadDataOptions[] = '--application='.$options['application']; |
|---|
| 98 |
} |
|---|
| 99 |
if (!empty($options['dir'])) |
|---|
| 100 |
{ |
|---|
| 101 |
$loadDataOptions[] = '--dir=' . implode(' --dir=', $options['dir']); |
|---|
| 102 |
} |
|---|
| 103 |
|
|---|
| 104 |
$loadData->run(array(), $loadDataOptions); |
|---|
| 105 |
} |
|---|
| 106 |
|
|---|
| 107 |
return $ret; |
|---|
| 108 |
} |
|---|
| 109 |
} |
|---|