Development

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

You must first sign up to be able to contribute.

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

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

[1.2, 1.3] Fixes issue with tasks that use the drop db task not stopping with confirmation is false (closes #5903)

  • 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  * Drops Databases, 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 sfDoctrineBuildAllReloadTask 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-reload');
40     $this->namespace = 'doctrine';
41     $this->name = 'build-all-reload';
42     $this->briefDescription = 'Generates Doctrine model, SQL, initializes database, and load data';
43
44     $this->detailedDescription = <<<EOF
45 The [doctrine:build-all-reload|INFO] task is a shortcut for five other tasks:
46
47   [./symfony doctrine:build-all-reload|INFO]
48
49 The task is equivalent to:
50
51   [./symfony doctrine:drop-db|INFO]
52   [./symfony doctrine:build-db|INFO]
53   [./symfony doctrine:build-model|INFO]
54   [./symfony doctrine:insert-sql|INFO]
55   [./symfony doctrine:data-load|INFO]
56 EOF;
57   }
58
59   /**
60    * @see sfTask
61    */
62   protected function execute($arguments = array(), $options = array())
63   {
64     $dropDb = new sfDoctrineDropDbTask($this->dispatcher, $this->formatter);
65     $dropDb->setCommandApplication($this->commandApplication);
66
67     $dropDbOptions = array();
68     $dropDbOptions[] = '--env='.$options['env'];
69     if (isset($options['no-confirmation']) && $options['no-confirmation'])
70     {
71       $dropDbOptions[] = '--no-confirmation';
72     }
73     if (isset($options['application']) && $options['application'])
74     {
75       $dropDbOptions[] = '--application=' . $options['application'];
76     }
77     $ret = $dropDb->run(array(), $dropDbOptions);
78
79     if ($ret)
80     {
81       return $ret;
82     }
83
84     $buildAllLoad = new sfDoctrineBuildAllLoadTask($this->dispatcher, $this->formatter);
85     $buildAllLoad->setCommandApplication($this->commandApplication);
86
87     $buildAllLoadOptions = array();
88     $buildAllLoadOptions[] = '--env='.$options['env'];
89     if (!empty($options['dir']))
90     {
91       $buildAllLoadOptions[] = '--dir=' . implode(' --dir=', $options['dir']);
92     }
93     if (isset($options['append']) && $options['append'])
94     {
95       $buildAllLoadOptions[] = '--append';
96     }
97     if (isset($options['application']) && $options['application'])
98     {
99       $buildAllLoadOptions[] = '--application=' . $options['application'];
100     }
101     if (isset($options['skip-forms']) && $options['skip-forms'])
102     {
103       $buildAllLoadOptions[] = '--skip-forms';
104     }
105     $buildAllLoad->run(array(), $buildAllLoadOptions);
106   }
107 }
Note: See TracBrowser for help on using the browser.