1 | <?php |
||
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 | 8 | public function __construct(Configuration $configuration) |
|
31 | |||
32 | 8 | public function getMigrationsInfos() |
|
33 | { |
||
34 | 8 | $numExecutedUnavailableMigrations = count($this->executedUnavailableMigrations); |
|
35 | 8 | $numNewMigrations = count(array_diff($this->availableMigrations, $this->executedMigrations)); |
|
36 | |||
37 | $infos = [ |
||
38 | 8 | 'Name' => $this->configuration->getName() ? $this->configuration->getName() : 'Doctrine Database Migrations', |
|
39 | 8 | 'Database Driver' => $this->configuration->getConnection()->getDriver()->getName(), |
|
40 | 8 | 'Database Name' => $this->configuration->getConnection()->getDatabase(), |
|
41 | 8 | 'Configuration Source' => $this->configuration instanceof AbstractFileConfiguration ? $this->configuration->getFile() : 'manually configured', |
|
42 | 8 | 'Version Table Name' => $this->configuration->getMigrationsTableName(), |
|
43 | 8 | 'Version Column Name' => $this->configuration->getMigrationsColumnName(), |
|
44 | 8 | 'Migrations Namespace' => $this->configuration->getMigrationsNamespace(), |
|
45 | 8 | 'Migrations Directory' => $this->configuration->getMigrationsDirectory(), |
|
46 | 8 | 'Previous Version' => $this->getFormattedVersionAlias('prev'), |
|
47 | 8 | 'Current Version' => $this->getFormattedVersionAlias('current'), |
|
48 | 8 | 'Next Version' => $this->getFormattedVersionAlias('next'), |
|
49 | 8 | 'Latest Version' => $this->getFormattedVersionAlias('latest'), |
|
50 | 8 | 'Executed Migrations' => count($this->executedMigrations), |
|
51 | 8 | 'Executed Unavailable Migrations' => $numExecutedUnavailableMigrations, |
|
52 | 8 | 'Available Migrations' => count($this->availableMigrations), |
|
53 | 8 | 'New Migrations' => $numNewMigrations, |
|
54 | ]; |
||
55 | |||
56 | 8 | return $infos; |
|
57 | } |
||
58 | |||
59 | 8 | private function getFormattedVersionAlias($alias) |
|
60 | { |
||
61 | 8 | $version = $this->configuration->resolveVersionAlias($alias); |
|
62 | //No version found |
||
63 | 8 | if ($version === null) { |
|
64 | 8 | if ($alias === 'next') { |
|
65 | 3 | return 'Already at latest version'; |
|
66 | } |
||
67 | |||
68 | 8 | if ($alias === 'prev') { |
|
69 | 8 | return 'Already at first version'; |
|
70 | } |
||
71 | } |
||
72 | //Before first version "virtual" version number |
||
73 | 8 | if ($version === '0') { |
|
74 | 8 | return '<comment>0</comment>'; |
|
75 | } |
||
76 | |||
77 | //Show normal version number |
||
78 | 8 | return $this->configuration->getDateTime($version) . ' (<comment>' . $version . '</comment>)'; |
|
79 | } |
||
80 | |||
81 | /** @var Version[] */ |
||
82 | public function getExecutedUnavailableMigrations() |
||
86 | } |
||
87 |