|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Arrilot\BitrixMigrations\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Arrilot\BitrixMigrations\Migrator; |
|
6
|
|
|
|
|
7
|
|
|
class StatusCommand extends AbstractCommand |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* Migrator instance. |
|
11
|
|
|
* |
|
12
|
|
|
* @var Migrator |
|
13
|
|
|
*/ |
|
14
|
|
|
protected $migrator; |
|
15
|
|
|
|
|
16
|
|
|
protected static $defaultName = 'status'; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Constructor. |
|
20
|
|
|
* |
|
21
|
|
|
* @param Migrator $migrator |
|
22
|
|
|
* @param string|null $name |
|
23
|
|
|
*/ |
|
24
|
|
|
public function __construct(Migrator $migrator, $name = null) |
|
25
|
|
|
{ |
|
26
|
|
|
$this->migrator = $migrator; |
|
27
|
|
|
|
|
28
|
|
|
parent::__construct($name); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Configures the current command. |
|
33
|
|
|
*/ |
|
34
|
|
|
protected function configure() |
|
35
|
|
|
{ |
|
36
|
|
|
$this->setDescription('Show status about last migrations'); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Execute the console command. |
|
41
|
|
|
* |
|
42
|
|
|
* @return null|int |
|
43
|
|
|
*/ |
|
44
|
|
|
protected function fire() |
|
45
|
|
|
{ |
|
46
|
|
|
$this->showOldMigrations(); |
|
47
|
|
|
|
|
48
|
|
|
$this->output->write("\r\n"); |
|
49
|
|
|
|
|
50
|
|
|
$this->showNewMigrations(); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Show old migrations. |
|
55
|
|
|
* |
|
56
|
|
|
* @return void |
|
57
|
|
|
*/ |
|
58
|
|
|
protected function showOldMigrations() |
|
59
|
|
|
{ |
|
60
|
|
|
$old = collect($this->migrator->getRanMigrations()); |
|
61
|
|
|
|
|
62
|
|
|
$this->output->writeln("<fg=yellow>Old migrations:\r\n</>"); |
|
63
|
|
|
|
|
64
|
|
|
$max = 5; |
|
65
|
|
|
if ($old->count() > $max) { |
|
66
|
|
|
$this->output->writeln('<fg=yellow>...</>'); |
|
67
|
|
|
|
|
68
|
|
|
$old = $old->take(-$max); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
foreach ($old as $migration) { |
|
72
|
|
|
$this->output->writeln("<fg=yellow>{$migration}.php</>"); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Show new migrations. |
|
78
|
|
|
* |
|
79
|
|
|
* @return void |
|
80
|
|
|
*/ |
|
81
|
|
|
protected function showNewMigrations() |
|
82
|
|
|
{ |
|
83
|
|
|
$new = collect($this->migrator->getMigrationsToRun()); |
|
84
|
|
|
|
|
85
|
|
|
$this->output->writeln("<fg=green>New migrations:\r\n</>"); |
|
86
|
|
|
|
|
87
|
|
|
foreach ($new as $migration) { |
|
88
|
|
|
$this->output->writeln("<fg=green>{$migration}.php</>"); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|