Completed
Push — master ( 38429b...fb3a3c )
by Joao
20:43
created

ResetCommand::execute()   B

Complexity

Conditions 4
Paths 14

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 24
rs 8.6845
cc 4
eloc 15
nc 14
nop 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: jg
5
 * Date: 17/06/16
6
 * Time: 21:52
7
 */
8
9
namespace ByJG\DbMigration\Console;
10
11
use Symfony\Component\Console\Input\InputInterface;
12
use Symfony\Component\Console\Output\OutputInterface;
13
use Symfony\Component\Console\Question\ConfirmationQuestion;
14
15
class ResetCommand extends ConsoleCommand
16
{
17
    protected function configure()
18
    {
19
        parent::configure();
20
        $this
21
            ->setName('reset')
22
            ->setDescription('Create a fresh new database')
23
            ->addOption('yes', null, null, 'Answer yes to any interactive question');
24
    }
25
26
    protected function execute(InputInterface $input, OutputInterface $output)
27
    {
28
        try {
29
            $helper = $this->getHelper('question');
30
            if (!$input->getOption('yes')) {
31
                $question = new ConfirmationQuestion(
32
                    'This will ERASE all of data in your data. Continue with this action? (y/N) ',
33
                    false
34
                );
35
36
                if (!$helper->ask($input, $output, $question)) {
37
                    $output->writeln('Aborted.');
38
39
                    return;
40
                }
41
            }
42
43
            parent::execute($input, $output);
44
            $this->migration->prepareEnvironment();
45
            $this->migration->reset($this->upTo);
46
        } catch (\Exception $ex) {
47
            $this->handleError($ex, $output);
48
        }
49
    }
50
}
51