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 Spiral\Migrations\State; |
21
|
|
|
use Symfony\Component\Console\Helper\Table; |
22
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
23
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
24
|
|
|
|
25
|
|
|
final class StatusCommand extends AbstractCommand |
26
|
|
|
{ |
27
|
|
|
protected const PENDING = '<fg=red>not executed yet</fg=red>'; |
28
|
|
|
|
29
|
|
|
protected static $defaultName = 'migrations:status'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* {@inheritdoc} |
33
|
|
|
*/ |
34
|
|
|
protected function defineDescription(): string |
35
|
|
|
{ |
36
|
|
|
return 'Get list of all available migrations and their statuses'; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* {@inheritdoc} |
41
|
|
|
*/ |
42
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
43
|
|
|
{ |
44
|
|
|
if (!$this->verifyConfigured($output)) { |
45
|
|
|
//Making sure migration is configured. |
46
|
|
|
return 1; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
if (empty($this->migrator->getMigrations())) { |
50
|
|
|
$output->writeln('<comment>No migrations were found.</comment>'); |
51
|
|
|
|
52
|
|
|
return 1; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$table = new Table($output); |
56
|
|
|
$table = $table->setHeaders(['Migration', 'Created at', 'Executed at']); |
57
|
|
|
|
58
|
|
|
foreach ($this->migrator->getMigrations() as $migration) { |
59
|
|
|
$state = $migration->getState(); |
60
|
|
|
|
61
|
|
|
$table->addRow([ |
62
|
|
|
$state->getName(), |
63
|
|
|
$state->getTimeCreated()->format('Y-m-d H:i:s'), |
64
|
|
|
$state->getStatus() === State::STATUS_PENDING |
65
|
|
|
? self::PENDING |
66
|
|
|
: '<info>' . $state->getTimeExecuted()->format('Y-m-d H:i:s') . '</info>', |
67
|
|
|
]); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$table->render(); |
71
|
|
|
|
72
|
|
|
return 0; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|