Completed
Pull Request — master (#177)
by
unknown
04:33
created

DropCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 16
rs 9.4285
cc 1
eloc 10
nc 1
nop 0
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 \Symfony\Component\Console\Input\InputInterface $input
30
     * @param \Symfony\Component\Console\Output\OutputInterface $output
31
     * @return int|void
32
     */
33
    protected function execute(InputInterface $input, OutputInterface $output)
34
    {
35
        $this->detectDbSettings($output);
36
        $dialog = $this->getHelperSet()->get('dialog');
37
        $dbHelper = $this->getHelper('database');
38
39
        if ($input->getOption('force')) {
40
            $shouldDrop = true;
41
        } else {
42
            $shouldDrop = $dialog->askConfirmation($output, '<question>Really drop database ' . $this->dbSettings['dbname'] . ' ?</question> <comment>[n]</comment>: ', false);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 175 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
43
        }
44
45
        if ($shouldDrop) {
46
            if ($input->getOption('tables')) {
47
                $dbHelper->dropTables($output);
48
            } else {
49
                $dbHelper->dropDatabase($output);
50
            }
51
        }
52
    }
53
}
54