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