|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Doctrine\DBAL\Migrations\Tools\Console\Helper; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use Doctrine\DBAL\Migrations\Configuration\AbstractFileConfiguration; |
|
7
|
|
|
use Doctrine\DBAL\Migrations\Configuration\Configuration; |
|
8
|
|
|
use Doctrine\DBAL\Migrations\Version; |
|
9
|
|
|
|
|
10
|
|
|
class MigrationStatusInfosHelper |
|
11
|
|
|
{ |
|
12
|
|
|
/** @var Version[] */ |
|
13
|
|
|
private $executedMigrations; |
|
14
|
|
|
|
|
15
|
|
|
/** @var Version[] */ |
|
16
|
|
|
private $availableMigrations; |
|
17
|
|
|
|
|
18
|
|
|
/** @var Version[] */ |
|
19
|
|
|
private $executedUnavailableMigrations; |
|
20
|
|
|
|
|
21
|
|
|
/** @var Configuration */ |
|
22
|
|
|
private $configuration; |
|
23
|
|
|
|
|
24
|
7 |
|
public function __construct(Configuration $configuration) |
|
25
|
|
|
{ |
|
26
|
7 |
|
$this->configuration = $configuration; |
|
27
|
7 |
|
$this->executedMigrations = $this->configuration->getMigratedVersions(); |
|
28
|
7 |
|
$this->availableMigrations = $this->configuration->getAvailableVersions(); |
|
29
|
7 |
|
$this->executedUnavailableMigrations = array_diff($this->executedMigrations, $this->availableMigrations); |
|
30
|
7 |
|
} |
|
31
|
|
|
|
|
32
|
7 |
|
public function getMigrationsInfos() |
|
33
|
|
|
{ |
|
34
|
7 |
|
$numExecutedUnavailableMigrations = count($this->executedUnavailableMigrations); |
|
35
|
7 |
|
$numNewMigrations = count(array_diff($this->availableMigrations, $this->executedMigrations)); |
|
36
|
|
|
|
|
37
|
|
|
$infos = [ |
|
38
|
7 |
|
'Name' => $this->configuration->getName() ? $this->configuration->getName() : 'Doctrine Database Migrations', |
|
39
|
7 |
|
'Database Driver' => $this->configuration->getConnection()->getDriver()->getName(), |
|
40
|
7 |
|
'Database Name' => $this->configuration->getConnection()->getDatabase(), |
|
41
|
7 |
|
'Configuration Source' => $this->configuration instanceof AbstractFileConfiguration ? $this->configuration->getFile() : 'manually configured', |
|
42
|
7 |
|
'Version Table Name' => $this->configuration->getMigrationsTableName(), |
|
43
|
7 |
|
'Version Column Name' => $this->configuration->getMigrationsColumnName(), |
|
44
|
7 |
|
'Migrations Namespace' => $this->configuration->getMigrationsNamespace(), |
|
45
|
7 |
|
'Migrations Directory' => $this->configuration->getMigrationsDirectory(), |
|
46
|
7 |
|
'Previous Version' => $this->getFormattedVersionAlias('prev'), |
|
47
|
7 |
|
'Current Version' => $this->getFormattedVersionAlias('current'), |
|
48
|
7 |
|
'Next Version' => $this->getFormattedVersionAlias('next'), |
|
49
|
7 |
|
'Latest Version' => $this->getFormattedVersionAlias('latest'), |
|
50
|
7 |
|
'Executed Migrations' => count($this->executedMigrations), |
|
51
|
7 |
|
'Executed Unavailable Migrations' => $numExecutedUnavailableMigrations, |
|
52
|
7 |
|
'Available Migrations' => count($this->availableMigrations), |
|
53
|
7 |
|
'New Migrations' => $numNewMigrations, |
|
54
|
7 |
|
]; |
|
55
|
|
|
|
|
56
|
7 |
|
return $infos; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
7 |
|
private function getFormattedVersionAlias($alias) |
|
60
|
|
|
{ |
|
61
|
7 |
|
$version = $this->configuration->resolveVersionAlias($alias); |
|
62
|
|
|
//No version found |
|
63
|
7 |
|
if ($version === null) { |
|
64
|
7 |
|
if ($alias == 'next') { |
|
65
|
|
|
|
|
66
|
3 |
|
return 'Already at latest version'; |
|
67
|
7 |
|
} elseif ($alias == 'prev') { |
|
68
|
|
|
|
|
69
|
7 |
|
return 'Already at first version'; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
//Before first version "virtual" version number |
|
73
|
7 |
|
if ($version === '0') { |
|
74
|
|
|
|
|
75
|
7 |
|
return '<comment>0</comment>'; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
//Show normal version number |
|
79
|
7 |
|
return $this->configuration->getDateTime($version) . ' (<comment>' . $version . '</comment>)'; |
|
80
|
|
|
|
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** @var Version[] */ |
|
84
|
|
|
public function getExecutedUnavailableMigrations() |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->executedUnavailableMigrations; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|