1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of Biurad opensource projects. |
7
|
|
|
* |
8
|
|
|
* PHP version 7.2 and above required |
9
|
|
|
* |
10
|
|
|
* @author Divine Niiquaye Ibok <[email protected]> |
11
|
|
|
* @copyright 2019 Biurad Group (https://biurad.com/) |
12
|
|
|
* @license https://opensource.org/licenses/BSD-3-Clause License |
13
|
|
|
* |
14
|
|
|
* For the full copyright and license information, please view the LICENSE |
15
|
|
|
* file that was distributed with this source code. |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
namespace Biurad\Cycle\Commands\Migrations; |
19
|
|
|
|
20
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
21
|
|
|
use Symfony\Component\Console\Input\InputOption; |
22
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
23
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
24
|
|
|
|
25
|
|
|
final class StartCommand extends AbstractCommand |
26
|
|
|
{ |
27
|
|
|
protected static $defaultName = 'migrations:start'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* {@inheritdoc} |
31
|
|
|
*/ |
32
|
|
|
protected function defineDescription(): string |
33
|
|
|
{ |
34
|
|
|
return 'Perform one or all outstanding migrations'; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* {@inheritdoc} |
39
|
|
|
*/ |
40
|
|
|
protected function defineOption(): array |
41
|
|
|
{ |
42
|
|
|
return [new InputOption('one', 'o', InputOption::VALUE_NONE, 'Execute only one (first) migration')]; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* {@inheritdoc} |
47
|
|
|
*/ |
48
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
49
|
|
|
{ |
50
|
|
|
$io = new SymfonyStyle($input, $output); |
51
|
|
|
|
52
|
|
|
if (!$this->verifyConfigured($output) || !$this->verifyEnvironment($input, $io)) { |
53
|
|
|
return 1; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$found = false; |
57
|
|
|
$count = $input->getOption('one') ? 1 : \PHP_INT_MAX; |
58
|
|
|
|
59
|
|
|
while ($count > 0 && ($migration = $this->migrator->run())) { |
60
|
|
|
$found = true; |
61
|
|
|
$count--; |
62
|
|
|
|
63
|
|
|
$io->newLine(); |
64
|
|
|
$output->write( |
65
|
|
|
\sprintf( |
66
|
|
|
"<info>Migration <comment>%s</comment> was successfully executed.</info>\n", |
67
|
|
|
$migration->getState()->getName() |
68
|
|
|
) |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
if (!$found) { |
73
|
|
|
$io->error('No outstanding migrations were found'); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return 0; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|