setAliases(['list-migrations'])
->setDescription('Display a list of all available migrations and their status.')
->setHelp(<<<'EOT'
The %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 fn (AvailableMigration $availableMigration): Version => $availableMigration->getVersion(), $availableMigrations->getItems());
$executedVersions = array_map(static fn (ExecutedMigration $executedMigration): Version => $executedMigration->getVersion(), $executedMigrations->getItems());
$versions = array_unique(array_merge($availableVersions, $executedVersions));
$comparator = $this->getDependencyFactory()->getVersionComparator();
uasort($versions, $comparator->compare(...));
return $versions;
}
}