setAliases(['list-migrations']) ->setDescription('Display a list of all available migrations and their status.') ->setHelp(<<%command.name% command outputs a list of all available migrations and their status: %command.full_name% EOT ); parent::configure(); } protected function execute(InputInterface $input, OutputInterface $output): int { $versions = $this->getSortedVersions( $this->getDependencyFactory()->getMigrationPlanCalculator()->getMigrations(), // available migrations $this->getDependencyFactory()->getMetadataStorage()->getExecutedMigrations() // executed migrations ); $this->getDependencyFactory()->getMigrationStatusInfosHelper()->listVersions($versions, $output); return 0; } /** * @return Version[] */ private function getSortedVersions(AvailableMigrationsList $availableMigrations, ExecutedMigrationsList $executedMigrations): array { $availableVersions = array_map(static function (AvailableMigration $availableMigration): Version { return $availableMigration->getVersion(); }, $availableMigrations->getItems()); $executedVersions = array_map(static function (ExecutedMigration $executedMigration): Version { return $executedMigration->getVersion(); }, $executedMigrations->getItems()); $versions = array_unique(array_merge($availableVersions, $executedVersions)); $comparator = $this->getDependencyFactory()->getVersionComparator(); uasort($versions, static function (Version $a, Version $b) use ($comparator): int { return $comparator->compare($a, $b); }); return $versions; } }