/
MigrationsRollupDoctrineCommand.php
53 lines (42 loc) · 1.93 KB
/
MigrationsRollupDoctrineCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
declare(strict_types=1);
namespace Doctrine\Bundle\MigrationsBundle\Command;
use Doctrine\Migrations\Tools\Console\Command\RollupCommand;
use InvalidArgumentException;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Command for rolling up your historical migration versions and inserting the dumped schema version.
*/
class MigrationsRollupDoctrineCommand extends RollupCommand
{
protected function configure() : void
{
parent::configure();
$this
->setName('doctrine:migrations:rollup')
->addOption('db', null, InputOption::VALUE_REQUIRED, 'The database connection to use for this command.')
->addOption('em', null, InputOption::VALUE_REQUIRED, 'The entity manager to use for this command.')
->addOption('shard', null, InputOption::VALUE_REQUIRED, 'The shard connection to use for this command.')
;
}
public function initialize(InputInterface $input, OutputInterface $output) : void
{
/** @var Application $application */
$application = $this->getApplication();
Helper\DoctrineCommandHelper::setApplicationHelper($application, $input);
$configuration = $this->getMigrationConfiguration($input, $output);
DoctrineCommand::configureMigrations($application->getKernel()->getContainer(), $configuration);
parent::initialize($input, $output);
}
public function execute(InputInterface $input, OutputInterface $output) : ?int
{
// EM and DB options cannot be set at same time
if ($input->getOption('em') !== null && $input->getOption('db') !== null) {
throw new InvalidArgumentException('Cannot set both "em" and "db" for command execution.');
}
return parent::execute($input, $output);
}
}