1 | <?php |
||
36 | class StatusCommand extends AbstractCommand |
||
37 | { |
||
38 | 11 | protected function configure() |
|
39 | { |
||
40 | $this |
||
41 | 11 | ->setName('migrations:status') |
|
42 | 11 | ->setDescription('View the status of a set of migrations.') |
|
43 | 11 | ->addOption('show-versions', null, InputOption::VALUE_NONE, 'This will display a list of all available migrations and their status') |
|
44 | 11 | ->setHelp(<<<EOT |
|
45 | 11 | The <info>%command.name%</info> command outputs the status of a set of migrations: |
|
46 | |||
47 | <info>%command.full_name%</info> |
||
48 | |||
49 | You can output a list of all available migrations and their status with <comment>--show-versions</comment>: |
||
50 | |||
51 | <info>%command.full_name% --show-versions</info> |
||
52 | EOT |
||
53 | ); |
||
54 | |||
55 | 11 | parent::configure(); |
|
56 | 11 | } |
|
57 | |||
58 | 9 | public function execute(InputInterface $input, OutputInterface $output) |
|
59 | { |
||
60 | 9 | $configuration = $this->getMigrationConfiguration($input, $output); |
|
61 | |||
62 | 9 | $infos = new MigrationStatusInfosHelper($configuration); |
|
63 | |||
64 | 9 | $output->writeln("\n <info>==</info> Configuration\n"); |
|
65 | 9 | foreach ($infos->getMigrationsInfos() as $name => $value) { |
|
66 | 9 | if ($name == 'New Migrations') { |
|
|
|||
67 | 9 | $value = $value > 0 ? '<question>' . $value . '</question>' : 0; |
|
68 | } |
||
69 | 9 | if($name == 'Executed Unavailable Migrations') { |
|
70 | 9 | $value = $value > 0 ? '<error>' . $value . '</error>' : 0; |
|
71 | } |
||
72 | 9 | $this->writeStatusInfosLineAligned($output, $name, $value); |
|
73 | } |
||
74 | |||
75 | 9 | if ($input->getOption('show-versions')) { |
|
76 | 1 | if ($migrations = $configuration->getMigrations()) { |
|
77 | 1 | $output->writeln("\n <info>==</info> Available Migration Versions\n"); |
|
78 | |||
79 | 1 | $this->showVersions($migrations, $configuration, $output); |
|
80 | } |
||
81 | |||
82 | 1 | if (count($infos->getExecutedUnavailableMigrations())) { |
|
83 | $output->writeln("\n <info>==</info> Previously Executed Unavailable Migration Versions\n"); |
||
84 | foreach ($infos->getExecutedUnavailableMigrations() as $executedUnavailableMigration) { |
||
85 | $output->writeln(' <comment>>></comment> ' . $configuration->getDateTime($executedUnavailableMigration) . |
||
86 | ' (<comment>' . $executedUnavailableMigration . '</comment>)'); |
||
87 | } |
||
88 | } |
||
89 | } |
||
90 | 9 | } |
|
91 | |||
92 | 9 | private function writeStatusInfosLineAligned(OutputInterface $output, $title, $value) |
|
96 | |||
97 | 1 | private function showVersions($migrations, Configuration $configuration, OutputInterface $output) |
|
98 | { |
||
117 | } |
||
118 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.