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
|
|
|
|
20
|
|
|
$help = <<<HELP |
21
|
|
|
The command prompts before dropping the database. If --force option is specified it |
22
|
|
|
directly drops the database. |
23
|
|
|
The configured user in app/etc/local.xml must have "DROP" privileges. |
24
|
|
|
HELP; |
25
|
|
|
$this->setHelp($help); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param InputInterface $input |
30
|
|
|
* @param OutputInterface $output |
31
|
|
|
* |
32
|
|
|
* @return int|void |
33
|
|
|
*/ |
34
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
35
|
|
|
{ |
36
|
|
|
$this->detectDbSettings($output); |
37
|
|
|
|
38
|
|
|
$dialog = $this->getHelperSet()->get('dialog'); |
39
|
|
|
$dbHelper = $this->getHelper('database'); |
40
|
|
|
|
41
|
|
|
if ($input->getOption('force')) { |
42
|
|
|
$shouldDrop = true; |
43
|
|
|
} else { |
44
|
|
|
$shouldDrop = $dialog->askConfirmation( |
45
|
|
|
$output, |
46
|
|
|
'<question>Really drop database ' . $this->dbSettings['dbname'] . |
47
|
|
|
' ?</question> <comment>[n]</comment>: ', |
48
|
|
|
false |
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
if ($shouldDrop) { |
53
|
|
|
if ($input->getOption('tables')) { |
54
|
|
|
$dbHelper->dropTables($output); |
55
|
|
|
} else { |
56
|
|
|
$dbHelper->dropDatabase($output); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|