Completed
Push — master ( 424df6...6d7ac3 )
by Joao
9s
created

src/Console/DownCommand.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace ByJG\DbMigration\Console;
4
5
use Symfony\Component\Console\Input\InputInterface;
6
use Symfony\Component\Console\Output\OutputInterface;
7
use Symfony\Component\Console\Question\ConfirmationQuestion;
8
9 View Code Duplication
class DownCommand extends ConsoleCommand
0 ignored issues
show
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
10
{
11
    protected function configure()
12
    {
13
        parent::configure();
14
        $this
15
            ->setName('down')
16
            ->setDescription('Migrate down the database version.');
17
18
    }
19
20
    protected function execute(InputInterface $input, OutputInterface $output)
21
    {
22
        try {
23
            $versionInfo = $this->migration->getCurrentVersion();
24
            if (strpos($versionInfo['status'], 'partial') !== false) {
25
                $helper = $this->getHelper('question');
26
                $question = new ConfirmationQuestion(
27
                    'The database was not fully updated and maybe be unstable. Did you really want migrate the version? (y/N)',
28
                    false
29
                );
30
31
                if (!$helper->ask($input, $output, $question)) {
32
                    $output->writeln('Aborted.');
33
34
                    return;
35
                }
36
            }
37
38
            parent::execute($input, $output);
39
            $this->migration->down($this->upTo, true);
40
        } catch (\Exception $ex) {
41
            $this->handleError($ex, $output);
42
        }
43
    }
44
}
45