Development

/branches/1.3/lib/plugins/sfDoctrinePlugin/lib/task/sfDoctrineDropDbTask.class.php

You must first sign up to be able to contribute.

root/branches/1.3/lib/plugins/sfDoctrinePlugin/lib/task/sfDoctrineDropDbTask.class.php

Revision 24341, 3.1 kB (checked in by Kris.Wallsmith, 4 years ago)

[1.3, 1.4] fixed fatal error in doctrine build/drop db tasks when no application exists (closes #7686, refs #7633)

  • 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) 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 database for current model.
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 sfDoctrineDropDbTask extends sfDoctrineBaseTask
24 {
25   /**
26    * @see sfTask
27    */
28   protected function configure()
29   {
30     $this->addArguments(array(
31       new sfCommandArgument('database', sfCommandArgument::OPTIONAL | sfCommandArgument::IS_ARRAY, 'A specific database'),
32     ));
33
34     $this->addOptions(array(
35       new sfCommandOption('application', null, sfCommandOption::PARAMETER_OPTIONAL, 'The application name', true),
36       new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),
37       new sfCommandOption('no-confirmation', null, sfCommandOption::PARAMETER_NONE, 'Whether to force dropping of the database')
38     ));
39
40     $this->aliases = array('doctrine-drop-db');
41     $this->namespace = 'doctrine';
42     $this->name = 'drop-db';
43     $this->briefDescription = 'Drops database for current model';
44
45     $this->detailedDescription = <<<EOF
46 The [doctrine:drop-db|INFO] task drops one or more databases based on
47 configuration in [config/databases.yml|COMMENT]:
48
49   [./symfony doctrine:drop-db|INFO]
50
51 You will be prompted for confirmation before any databases are dropped unless
52 you provide the [--no-confirmation|COMMENT] option:
53
54   [./symfony doctrine:drop-db --no-confirmation|INFO]
55
56 You can specify what databases to drop by providing their names:
57
58   [./symfony doctrine:drop-db slave1 slave2|INFO]
59 EOF;
60   }
61
62   /**
63    * @see sfTask
64    */
65   protected function execute($arguments = array(), $options = array())
66   {
67     $databaseManager = new sfDatabaseManager($this->configuration);
68     $databases = $this->getDoctrineDatabases($databaseManager, count($arguments['database']) ? $arguments['database'] : null);
69
70     $environment = $this->configuration instanceof sfApplicationConfiguration ? $this->configuration->getEnvironment() : 'all';
71
72     if (
73       !$options['no-confirmation']
74       &&
75       !$this->askConfirmation(array_merge(
76         array(sprintf('This command will remove all data in the following "%s" connection(s):', $environment), ''),
77         array_map(create_function('$v', 'return \' - \'.$v;'), array_keys($databases)),
78         array('', 'Are you sure you want to proceed? (y/N)')
79       ), 'QUESTION_LARGE', false)
80     )
81     {
82       $this->logSection('doctrine', 'task aborted');
83
84       return 1;
85     }
86
87     foreach ($databases as $name => $database)
88     {
89       $this->logSection('doctrine', sprintf('Dropping "%s" database', $name));
90       try
91       {
92         $database->getDoctrineConnection()->dropDatabase();
93       }
94       catch (Exception $e)
95       {
96         $this->logSection('doctrine', $e->getMessage(), null, 'ERROR');
97       }
98     }
99   }
100 }
101
Note: See TracBrowser for help on using the browser.