-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMigrateCommand.php
91 lines (72 loc) · 2.8 KB
/
MigrateCommand.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
/*
* This file is part of the PHPCR Migrations package
*
* (c) Daniel Leech <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPCR\PhpcrMigrationsBundle\Command;
use PHPCR\Migrations\MigratorFactory;
use PHPCR\PhpcrMigrationsBundle\ContainerAwareInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface as SymfonyContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class MigrateCommand extends Command
{
/**
* @var string[]
*/
private array $actions = [
'up', 'down', 'top', 'bottom',
];
public function __construct(
private MigratorFactory $factory,
private ContainerInterface $container
) {
parent::__construct();
}
public function configure(): void
{
$this->setName('phpcr:migrations:migrate');
$this->addArgument('to', InputArgument::OPTIONAL, sprintf(
'Version name to migrate to, or an action: "<comment>%s</comment>"',
implode('</comment>", "<comment>', $this->actions)
));
$this->setDescription('Migrate the content repository between versions');
$this->setHelp(<<<EOT
Migrate to a specific version or perform an action.
By default, it will migrate to the latest version:
$ %command.full_name%
You can migrate to a specific version (either in the "past" or "future"):
$ %command.full_name% 201504011200
Or specify an action
$ %command.full_name% <action>
Action can be one of:
- <comment>up</comment>: Migrate one version up
- <comment>down</comment>: Migrate one version down
- <comment>top</comment>: Migrate to the latest version
- <comment>bottom</comment>: Revert all migrations
EOT
);
}
public function execute(InputInterface $input, OutputInterface $output): int
{
$to = $input->getArgument('to');
$migrator = $this->factory->getMigrator();
foreach ($migrator->getVersions() as $version) {
if ($version instanceof ContainerAwareInterface) {
$version->setContainer($this->container);
} elseif ($version instanceof SymfonyContainerAwareInterface) {
$version->setContainer($this->container);
@trigger_error('Relying on '.SymfonyContainerAwareInterface::class.' is deprecated and will break when upgrading to Symfony 7. Use '.ContainerAwareInterface::class.' instead.', \E_USER_DEPRECATED);
}
}
$migrator->migrate($to, $output);
return 0;
}
}