55namespace Doctrine \Bundle \MigrationsBundle \Collector ;
66
77use Doctrine \Migrations \DependencyFactory ;
8+ use Doctrine \Migrations \Metadata \AvailableMigration ;
89use Doctrine \Migrations \Metadata \AvailableMigrationsList ;
10+ use Doctrine \Migrations \Metadata \ExecutedMigration ;
911use Doctrine \Migrations \Metadata \ExecutedMigrationsList ;
1012use Doctrine \Migrations \Metadata \Storage \TableMetadataStorageConfiguration ;
1113use Symfony \Component \HttpFoundation \Request ;
@@ -28,10 +30,14 @@ public function collect(Request $request, Response $response, \Throwable $except
2830 $ planCalculator = $ this ->dependencyFactory ->getMigrationPlanCalculator ();
2931 $ statusCalculator = $ this ->dependencyFactory ->getMigrationStatusCalculator ();
3032
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 ());
3541
3642 $ this ->data ['storage ' ] = get_class ($ metadataStorage );
3743 $ configuration = $ this ->dependencyFactory ->getConfiguration ();
@@ -63,13 +69,42 @@ public function reset()
6369 $ this ->data = [];
6470 }
6571
66- /**
67- * @param AvailableMigrationsList|ExecutedMigrationsList $migrationsList
68- */
69- private function flattenMigrations ($ migrationsList ): array
72+ private function flattenAvailableMigrations (AvailableMigrationsList $ migrationsList , ?ExecutedMigrationsList $ executedMigrations = null ): array
7073 {
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+ ];
73108 }, $ migrationsList ->getItems ());
74109 }
75110}
0 commit comments