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\ExecutedMigrationsSet; |
11
|
|
|
use Doctrine\Migrations\Metadata\Storage\MetadataStorage; |
12
|
|
|
use Doctrine\Migrations\MigrationRepository; |
13
|
|
|
use function array_filter; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* The MigrationPlanCalculator is responsible for calculating the plan for migrating from the current |
17
|
|
|
* version to another version. |
18
|
|
|
*/ |
19
|
|
|
final class CurrentMigrationStatusCalculator implements MigrationStatusCalculator |
20
|
|
|
{ |
21
|
|
|
/** @var MigrationRepository */ |
22
|
|
|
private $migrationRepository; |
23
|
|
|
|
24
|
|
|
/** @var MetadataStorage */ |
25
|
|
|
private $metadataStorage; |
26
|
|
|
|
27
|
41 |
|
public function __construct(MigrationRepository $migrationRepository, MetadataStorage $metadataStorage) |
28
|
|
|
{ |
29
|
41 |
|
$this->migrationRepository = $migrationRepository; |
30
|
41 |
|
$this->metadataStorage = $metadataStorage; |
31
|
41 |
|
} |
32
|
|
|
|
33
|
19 |
|
public function getExecutedUnavailableMigrations() : ExecutedMigrationsSet |
34
|
|
|
{ |
35
|
19 |
|
$executedMigrationsSet = $this->metadataStorage->getExecutedMigrations(); |
36
|
19 |
|
$availableMigrationsSet = $this->migrationRepository->getMigrations(); |
37
|
|
|
|
38
|
|
|
return new ExecutedMigrationsSet(array_filter($executedMigrationsSet->getItems(), static function (ExecutedMigration $migrationInfo) use ($availableMigrationsSet) : bool { |
39
|
12 |
|
return ! $availableMigrationsSet->hasMigration($migrationInfo->getVersion()); |
40
|
19 |
|
})); |
41
|
|
|
} |
42
|
|
|
|
43
|
14 |
|
public function getNewMigrations() : AvailableMigrationsList |
44
|
|
|
{ |
45
|
14 |
|
$executedMigrationsSet = $this->metadataStorage->getExecutedMigrations(); |
46
|
14 |
|
$availableMigrationsSet = $this->migrationRepository->getMigrations(); |
47
|
|
|
|
48
|
|
|
return new AvailableMigrationsList(array_filter($availableMigrationsSet->getItems(), static function (AvailableMigration $migrationInfo) use ($executedMigrationsSet) : bool { |
49
|
10 |
|
return ! $executedMigrationsSet->hasMigration($migrationInfo->getVersion()); |
50
|
14 |
|
})); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|