| @@ 15-53 (lines=39) @@ | ||
| 12 | /** |
|
| 13 | * The CurrentCommand class is responsible for outputting what your current version is. |
|
| 14 | */ |
|
| 15 | final class CurrentCommand extends DoctrineCommand |
|
| 16 | { |
|
| 17 | /** @var string */ |
|
| 18 | protected static $defaultName = 'migrations:current'; |
|
| 19 | ||
| 20 | protected function configure() : void |
|
| 21 | { |
|
| 22 | $this |
|
| 23 | ->setAliases(['current']) |
|
| 24 | ->setDescription('Outputs the current version'); |
|
| 25 | ||
| 26 | parent::configure(); |
|
| 27 | } |
|
| 28 | ||
| 29 | protected function execute(InputInterface $input, OutputInterface $output) : int |
|
| 30 | { |
|
| 31 | $aliasResolver = $this->getDependencyFactory()->getVersionAliasResolver(); |
|
| 32 | ||
| 33 | $version = $aliasResolver->resolveVersionAlias('current'); |
|
| 34 | if ((string) $version === '0') { |
|
| 35 | $description = '(No migration executed yet)'; |
|
| 36 | } else { |
|
| 37 | try { |
|
| 38 | $availableMigration = $this->getDependencyFactory()->getMigrationRepository()->getMigration($version); |
|
| 39 | $description = $availableMigration->getMigration()->getDescription(); |
|
| 40 | } catch (MigrationClassNotFound $e) { |
|
| 41 | $description = '(Migration info not available)'; |
|
| 42 | } |
|
| 43 | } |
|
| 44 | ||
| 45 | $this->io->text(sprintf( |
|
| 46 | "<info>%s</info>%s\n", |
|
| 47 | (string) $version, |
|
| 48 | $description !== '' ? ' - ' . $description : '' |
|
| 49 | )); |
|
| 50 | ||
| 51 | return 0; |
|
| 52 | } |
|
| 53 | } |
|
| 54 | ||
| @@ 15-50 (lines=36) @@ | ||
| 12 | /** |
|
| 13 | * The LatestCommand class is responsible for outputting what your latest version is. |
|
| 14 | */ |
|
| 15 | final class LatestCommand extends DoctrineCommand |
|
| 16 | { |
|
| 17 | /** @var string */ |
|
| 18 | protected static $defaultName = 'migrations:latest'; |
|
| 19 | ||
| 20 | protected function configure() : void |
|
| 21 | { |
|
| 22 | $this |
|
| 23 | ->setAliases(['latest']) |
|
| 24 | ->setDescription('Outputs the latest version'); |
|
| 25 | ||
| 26 | parent::configure(); |
|
| 27 | } |
|
| 28 | ||
| 29 | protected function execute(InputInterface $input, OutputInterface $output) : int |
|
| 30 | { |
|
| 31 | $aliasResolver = $this->getDependencyFactory()->getVersionAliasResolver(); |
|
| 32 | ||
| 33 | try { |
|
| 34 | $version = $aliasResolver->resolveVersionAlias('latest'); |
|
| 35 | $availableMigration = $this->getDependencyFactory()->getMigrationRepository()->getMigration($version); |
|
| 36 | $description = $availableMigration->getMigration()->getDescription(); |
|
| 37 | } catch (NoMigrationsToExecute $e) { |
|
| 38 | $version = '0'; |
|
| 39 | $description = ''; |
|
| 40 | } |
|
| 41 | ||
| 42 | $this->io->text(sprintf( |
|
| 43 | "<info>%s</info>%s\n", |
|
| 44 | $version, |
|
| 45 | $description !== '' ? ' - ' . $description : '' |
|
| 46 | )); |
|
| 47 | ||
| 48 | return 0; |
|
| 49 | } |
|
| 50 | } |
|
| 51 | ||