Development

/branches/1.2/lib/plugins/sfDoctrinePlugin/lib/task/sfDoctrineBuildAllLoadTask.class.php

You must first sign up to be able to contribute.

root/branches/1.2/lib/plugins/sfDoctrinePlugin/lib/task/sfDoctrineBuildAllLoadTask.class.php

Revision 18971, 3.6 kB (checked in by Jonathan.Wage, 6 years ago)

[1.2, 1.3] sfDoctrinePlugin: Fixing issue where application option was not passed to load data task

  • Property svn:keywords set to Id Date Author Revision HeadURL
Line 
1 <?php
2
3 /*
4  * This file is part of the symfony package.
5  * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
6  * (c) Jonathan H. Wage <jonwage@gmail.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 require_once(dirname(__FILE__).'/sfDoctrineBaseTask.class.php');
13
14 /**
15  * Creates Databases, Generates Doctrine model, SQL, initializes database, and load data.
16  *
17  * @package    symfony
18  * @subpackage doctrine
19  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
20  * @author     Jonathan H. Wage <jonwage@gmail.com>
21  * @version    SVN: $Id$
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 }
Note: See TracBrowser for help on using the browser.