|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace N98\Magento\Command\Database; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
6
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
7
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
8
|
|
|
|
|
9
|
|
|
class DropCommand extends AbstractDatabaseCommand |
|
10
|
|
|
{ |
|
11
|
|
|
protected function configure() |
|
12
|
|
|
{ |
|
13
|
|
|
$this |
|
14
|
|
|
->setName('db:drop') |
|
15
|
|
|
->addOption('tables', 't', InputOption::VALUE_NONE, 'Drop all tables instead of dropping the database') |
|
16
|
|
|
->addOption('force', 'f', InputOption::VALUE_NONE, 'Force') |
|
17
|
|
|
->setDescription('Drop current database'); |
|
18
|
|
|
|
|
19
|
|
|
$help = <<<HELP |
|
20
|
|
|
The command prompts before dropping the database. If --force option is specified it |
|
21
|
|
|
directly drops the database. |
|
22
|
|
|
The configured user in app/etc/local.xml must have "DROP" privileges. |
|
23
|
|
|
HELP; |
|
24
|
|
|
$this->setHelp($help); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input |
|
29
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output |
|
30
|
|
|
* @return int|void |
|
31
|
|
|
*/ |
|
32
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
33
|
|
|
{ |
|
34
|
|
|
$this->detectDbSettings($output); |
|
35
|
|
|
$dialog = $this->getHelperSet()->get('dialog'); |
|
36
|
|
|
$dbHelper = $this->getHelper('database'); |
|
37
|
|
|
|
|
38
|
|
|
if ($input->getOption('force')) { |
|
39
|
|
|
$shouldDrop = true; |
|
40
|
|
|
} else { |
|
41
|
|
|
$shouldDrop = $dialog->askConfirmation( |
|
42
|
|
|
$output, |
|
43
|
|
|
'<question>Really drop database ' . |
|
44
|
|
|
$this->dbSettings['dbname'] . ' ?</question> <comment>[n]</comment>: ', |
|
45
|
|
|
false |
|
46
|
|
|
); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
if ($shouldDrop) { |
|
50
|
|
|
if ($input->getOption('tables')) { |
|
51
|
|
|
$dbHelper->dropTables($output); |
|
52
|
|
|
} else { |
|
53
|
|
|
$dbHelper->dropDatabase($output); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|