5
5
namespace Doctrine \Bundle \MigrationsBundle \Collector ;
6
6
7
7
use Doctrine \Migrations \DependencyFactory ;
8
+ use Doctrine \Migrations \Metadata \AvailableMigration ;
8
9
use Doctrine \Migrations \Metadata \AvailableMigrationsList ;
10
+ use Doctrine \Migrations \Metadata \ExecutedMigration ;
9
11
use Doctrine \Migrations \Metadata \ExecutedMigrationsList ;
10
12
use Doctrine \Migrations \Metadata \Storage \TableMetadataStorageConfiguration ;
11
13
use Symfony \Component \HttpFoundation \Request ;
@@ -28,10 +30,14 @@ public function collect(Request $request, Response $response, \Throwable $except
28
30
$ planCalculator = $ this ->dependencyFactory ->getMigrationPlanCalculator ();
29
31
$ statusCalculator = $ this ->dependencyFactory ->getMigrationStatusCalculator ();
30
32
31
- $ this ->data ['available_migrations ' ] = $ this ->flattenMigrations ($ planCalculator ->getMigrations ());
32
- $ this ->data ['executed_migrations ' ] = $ this ->flattenMigrations ($ metadataStorage ->getExecutedMigrations ());
33
- $ this ->data ['new_migrations ' ] = $ this ->flattenMigrations ($ statusCalculator ->getNewMigrations ());
34
- $ this ->data ['unavailable_migrations ' ] = $ this ->flattenMigrations ($ statusCalculator ->getExecutedUnavailableMigrations ());
33
+ $ executedMigrations = $ metadataStorage ->getExecutedMigrations ();
34
+ $ availableMigrations = $ planCalculator ->getMigrations ();
35
+
36
+ $ this ->data ['available_migrations ' ] = $ this ->flattenAvailableMigrations ($ availableMigrations , $ executedMigrations );
37
+ $ this ->data ['executed_migrations ' ] = $ this ->flattenExecutedMigrations ($ executedMigrations , $ availableMigrations );
38
+
39
+ $ this ->data ['new_migrations ' ] = $ this ->flattenAvailableMigrations ($ statusCalculator ->getNewMigrations ());
40
+ $ this ->data ['unavailable_migrations ' ] = $ this ->flattenExecutedMigrations ($ statusCalculator ->getExecutedUnavailableMigrations ());
35
41
36
42
$ this ->data ['storage ' ] = get_class ($ metadataStorage );
37
43
$ configuration = $ this ->dependencyFactory ->getConfiguration ();
@@ -63,13 +69,42 @@ public function reset()
63
69
$ this ->data = [];
64
70
}
65
71
66
- /**
67
- * @param AvailableMigrationsList|ExecutedMigrationsList $migrationsList
68
- */
69
- private function flattenMigrations ($ migrationsList ): array
72
+ private function flattenAvailableMigrations (AvailableMigrationsList $ migrationsList , ?ExecutedMigrationsList $ executedMigrations = null ): array
70
73
{
71
- return array_map (static function ($ migration ) {
72
- return (string )$ migration ->getVersion ();
74
+ return array_map (static function (AvailableMigration $ migration ) use ($ executedMigrations ) {
75
+ $ executedMigration = $ executedMigrations && $ executedMigrations ->hasMigration ($ migration ->getVersion ())
76
+ ? $ executedMigrations ->getMigration ($ migration ->getVersion ())
77
+ : null ;
78
+
79
+ return [
80
+ 'version ' => (string )$ migration ->getVersion (),
81
+ 'is_new ' => !$ executedMigration ,
82
+ 'is_unavailable ' => false ,
83
+ 'description ' => $ migration ->getMigration ()->getDescription (),
84
+ 'executed_at ' => $ executedMigration ? $ executedMigration ->getExecutedAt () : null ,
85
+ 'execution_time ' => $ executedMigration ? $ executedMigration ->getExecutionTime () : null ,
86
+ 'file ' => (new \ReflectionClass ($ migration ->getMigration ()))->getFileName (),
87
+ ];
88
+ }, $ migrationsList ->getItems ());
89
+ }
90
+
91
+ private function flattenExecutedMigrations (ExecutedMigrationsList $ migrationsList , ?AvailableMigrationsList $ availableMigrations = null ): array
92
+ {
93
+ return array_map (static function (ExecutedMigration $ migration ) use ($ availableMigrations ) {
94
+
95
+ $ availableMigration = $ availableMigrations && $ availableMigrations ->hasMigration ($ migration ->getVersion ())
96
+ ? $ availableMigrations ->getMigration ($ migration ->getVersion ())->getMigration ()
97
+ : null ;
98
+
99
+ return [
100
+ 'version ' => (string )$ migration ->getVersion (),
101
+ 'is_new ' => false ,
102
+ 'is_unavailable ' => !$ availableMigration ,
103
+ 'description ' => $ availableMigration ? $ availableMigration ->getDescription () : null ,
104
+ 'executed_at ' => $ migration ->getExecutedAt (),
105
+ 'execution_time ' => $ migration ->getExecutionTime (),
106
+ 'file ' => $ availableMigration ? (new \ReflectionClass ($ availableMigration ))->getFileName () : null ,
107
+ ];
73
108
}, $ migrationsList ->getItems ());
74
109
}
75
110
}
0 commit comments