Failed Conditions
Pull Request — master (#968)
by Edi
02:04
created

RollupCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 12
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 1
rs 9.8666
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Migrations\Tools\Console\Command;
6
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
use function sprintf;
10
11
/**
12
 * The RollupCommand class is responsible for deleting all previously executed migrations from the versions table
13
 * and marking the freshly dumped schema migration (that was created with DumpSchemaCommand) as migrated.
14
 */
15
final class RollupCommand extends DoctrineCommand
16
{
17
    /** @var string */
18
    protected static $defaultName = 'migrations:rollup';
19
20 2
    protected function configure() : void
21
    {
22 2
        parent::configure();
23
24
        $this
25 2
            ->setAliases(['rollup'])
26 2
            ->setDescription('Rollup migrations by deleting all tracked versions and insert the one version that exists.')
27 2
            ->setHelp(<<<EOT
28 2
The <info>%command.name%</info> command rolls up migrations by deleting all tracked versions and
29
inserts the one version that exists that was created with the <info>migrations:dump-schema</info> command.
30
31
    <info>%command.full_name%</info>
32
33
To dump your schema to a migration version you can use the <info>migrations:dump-schema</info> command.
34
EOT
35
            );
36 2
    }
37
38 2
    protected function execute(InputInterface $input, OutputInterface $output) : int
39
    {
40 2
        $question = 'WARNING! You are about to execute a database migration that could result in schema changes and data loss. Are you sure you wish to continue?';
41
42 2
        if (! $this->canExecute($question, $input)) {
43
            $this->io->error('Migration cancelled!');
44
45
            return 3;
46
        }
47
48 2
        $this->getDependencyFactory()->getMetadataStorage()->ensureInitialized();
49 2
        $version = $this->getDependencyFactory()->getRollup()->rollup();
50
51 2
        $this->io->success(sprintf(
52 2
            'Rolled up migrations to version <info>%s</info>',
53 2
            (string) $version
54
        ));
55
56 2
        return 0;
57
    }
58
}
59