|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Doctrine\Migrations\Version; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\Migrations\Metadata\AvailableMigration; |
|
8
|
|
|
use Doctrine\Migrations\Metadata\AvailableMigrationsList; |
|
9
|
|
|
use Doctrine\Migrations\Metadata\ExecutedMigration; |
|
10
|
|
|
use Doctrine\Migrations\Metadata\ExecutedMigrationsList; |
|
11
|
|
|
use Doctrine\Migrations\Metadata\Storage\MetadataStorage; |
|
12
|
|
|
use function array_filter; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* The MigrationPlanCalculator is responsible for calculating the plan for migrating from the current |
|
16
|
|
|
* version to another version. |
|
17
|
|
|
*/ |
|
18
|
|
|
final class CurrentMigrationStatusCalculator implements MigrationStatusCalculator |
|
19
|
|
|
{ |
|
20
|
|
|
/** @var MigrationPlanCalculator */ |
|
21
|
|
|
private $migrationPlanCalculator; |
|
22
|
|
|
|
|
23
|
|
|
/** @var MetadataStorage */ |
|
24
|
|
|
private $metadataStorage; |
|
25
|
|
|
|
|
26
|
55 |
|
public function __construct( |
|
27
|
|
|
MigrationPlanCalculator $migrationPlanCalculator, |
|
28
|
|
|
MetadataStorage $metadataStorage |
|
29
|
|
|
) { |
|
30
|
55 |
|
$this->migrationPlanCalculator = $migrationPlanCalculator; |
|
31
|
55 |
|
$this->metadataStorage = $metadataStorage; |
|
32
|
55 |
|
} |
|
33
|
|
|
|
|
34
|
25 |
View Code Duplication |
public function getExecutedUnavailableMigrations() : ExecutedMigrationsList |
|
35
|
|
|
{ |
|
36
|
25 |
|
$executedMigrations = $this->metadataStorage->getExecutedMigrations(); |
|
37
|
25 |
|
$availableMigration = $this->migrationPlanCalculator->getMigrations(); |
|
38
|
|
|
|
|
39
|
|
|
return new ExecutedMigrationsList(array_filter($executedMigrations->getItems(), static function (ExecutedMigration $migrationInfo) use ($availableMigration) : bool { |
|
40
|
12 |
|
return ! $availableMigration->hasMigration($migrationInfo->getVersion()); |
|
41
|
25 |
|
})); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
17 |
View Code Duplication |
public function getNewMigrations() : AvailableMigrationsList |
|
45
|
|
|
{ |
|
46
|
17 |
|
$executedMigrations = $this->metadataStorage->getExecutedMigrations(); |
|
47
|
17 |
|
$availableMigration = $this->migrationPlanCalculator->getMigrations(); |
|
48
|
|
|
|
|
49
|
|
|
return new AvailableMigrationsList(array_filter($availableMigration->getItems(), static function (AvailableMigration $migrationInfo) use ($executedMigrations) : bool { |
|
50
|
13 |
|
return ! $executedMigrations->hasMigration($migrationInfo->getVersion()); |
|
51
|
17 |
|
})); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|