1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Schnittstabil\Dartisan\Commands; |
4
|
|
|
|
5
|
|
|
use Garden\Cli\Cli; |
6
|
|
|
use Garden\Cli\Args; |
7
|
|
|
use Garden\Cli\Table; |
8
|
|
|
use Illuminate\Database\Migrations\Migrator; |
9
|
|
|
use Schnittstabil\Dartisan\OutputInterface; |
10
|
|
|
|
11
|
|
|
class MigrateStatusCommand extends Command |
12
|
|
|
{ |
13
|
|
|
use DatabaseAwareCommandTrait; |
14
|
|
|
use MigrationAwareCommandTrait; |
15
|
|
|
|
16
|
|
|
public static $name = 'migrate:status'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var Migrator |
20
|
|
|
*/ |
21
|
|
|
protected $migrator; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
protected $migrationsPath; |
27
|
|
|
|
28
|
|
|
public function __construct( |
29
|
|
|
Args $args, |
30
|
|
|
OutputInterface $output, |
31
|
|
|
Migrator $migrator, |
32
|
|
|
string $migrationsPath |
33
|
|
|
) { |
34
|
|
|
parent::__construct($args, $output); |
35
|
|
|
$this->migrator = $migrator; |
36
|
|
|
$this->migrationsPath = $migrationsPath; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function run() |
40
|
|
|
{ |
41
|
|
|
if (!$this->migrator->repositoryExists()) { |
42
|
|
|
$this->output->error('No migration table found.'); |
|
|
|
|
43
|
|
|
|
44
|
|
|
return 1; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$path = $this->args->getOpt('path', $this->migrationsPath); |
48
|
|
|
$ran = $this->migrator->getRepository()->getRan(); |
49
|
|
|
$migrationFiles = $this->migrator->getMigrationFiles($path); |
50
|
|
|
$this->echoMigrationTable($ran, $migrationFiles); |
51
|
|
|
|
52
|
|
|
return 0; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @SuppressWarnings(PHPMD.ElseExpression) |
57
|
|
|
**/ |
58
|
|
|
protected function echoMigrationTable($ran, $migrationFiles) |
59
|
|
|
{ |
60
|
|
|
if (count($migrationFiles) === 0) { |
61
|
|
|
$this->output->info('No migration files found.'); |
|
|
|
|
62
|
|
|
|
63
|
|
|
return; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$table = new Table(); |
67
|
|
|
$table->row()->bold('Ran')->bold('Migration'); |
68
|
|
|
|
69
|
|
|
foreach ($migrationFiles as $migration) { |
70
|
|
|
$migrationName = $this->migrator->getMigrationName($migration); |
71
|
|
|
$table->row(); |
72
|
|
|
|
73
|
|
|
if (in_array($migrationName, $ran)) { |
74
|
|
|
$table->green('Y'); |
75
|
|
|
} else { |
76
|
|
|
$table->red('N'); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
$table->cell($migrationName); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
$table->write(); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
View Code Duplication |
public static function register(Cli $cli) |
86
|
|
|
{ |
87
|
|
|
$cli = static::registerDatabaseOpts($cli); |
88
|
|
|
$cli = static::registerMigrationOpts($cli); |
89
|
|
|
|
90
|
|
|
return $cli |
91
|
|
|
->command(static::$name) |
92
|
|
|
->description('Show the status of each migration.') |
93
|
|
|
->opt('path', 'The path of migrations files to be executed.'); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.