Skip to content

Commit

Permalink
add required console command return codes
Browse files Browse the repository at this point in the history
  • Loading branch information
FabriZZio committed Dec 26, 2019
1 parent 145f4b9 commit a250ad4
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 19 deletions.
6 changes: 4 additions & 2 deletions src/Phpmig/Console/Command/DownCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
$version = $input->getArgument('version');

if (!in_array($version, $versions)) {
return;
return 0;
}

if (!isset($migrations[$version])) {
return;
return 0;
}

$container = $this->getContainer();
$container['phpmig.migrator']->down($migrations[$version]);

return 0;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Phpmig/Console/Command/GenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function down()
'.' . str_replace(getcwd(), '', $path)
);

return;
return 0;
}

protected function transMigName($migrationName)
Expand Down
2 changes: 2 additions & 0 deletions src/Phpmig/Console/Command/MigrateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$container['phpmig.migrator']->up($migration);
}
}

return 0;
}
}
6 changes: 4 additions & 2 deletions src/Phpmig/Console/Command/RedoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,18 @@ protected function execute(InputInterface $input, OutputInterface $output)
$version = $input->getArgument('version');

if (!in_array($version, $versions)) {
return;
return 0;
}

if (!isset($migrations[$version])) {
return;
return 0;
}

$container = $this->getContainer();
$container['phpmig.migrator']->down($migrations[$version]);
$container['phpmig.migrator']->up($migrations[$version]);

return 0;
}
}

Expand Down
14 changes: 8 additions & 6 deletions src/Phpmig/Console/Command/RollbackCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$migrations = $this->getMigrations();
$versions = $this->getAdapter()->fetchAll();

$version = $input->getOption('target');

ksort($migrations);
Expand All @@ -64,9 +64,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
// Check we have at least 1 migration to revert
if (empty($versions) || $version == end($versions)) {
$output->writeln("<error>No migrations to rollback</error>");
return;
return 0;
}

// If no target version was supplied, revert the last migration
if (null === $version) {
// Get the migration before the last run migration
Expand All @@ -75,17 +75,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
} else {
// Get the first migration number
$first = reset($versions);

// If the target version is before the first migration, revert all migrations
if ($version < $first) {
$version = 0;
}
}

// Check the target version exists
if (0 !== $version && !isset($migrations[$version])) {
$output->writeln("<error>Target version ($version) not found</error>");
return;
return 0;
}

// Revert the migration(s)
Expand All @@ -100,5 +100,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$container['phpmig.migrator']->down($migration);
}
}

return 0;
}
}
12 changes: 6 additions & 6 deletions src/Phpmig/Console/Command/StatusCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$versions = $this->getAdapter()->fetchAll();
foreach($this->getMigrations() as $migration) {

if (in_array($migration->getVersion(), $versions)) {
$status = " <info>up</info> ";
unset($versions[array_search($migration->getVersion(), $versions)]);
Expand All @@ -63,23 +63,23 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$output->writeln(
$status .
sprintf(" %14s ", $migration->getVersion()) .
$status .
sprintf(" %14s ", $migration->getVersion()) .
" <comment>" . $migration->getName() . "</comment>"
);
}

foreach($versions as $missing) {
$output->writeln(
' <error>up</error> ' .
sprintf(" %14s ", $missing) .
' <error>up</error> ' .
sprintf(" %14s ", $missing) .
' <error>** MISSING **</error> '
);
}

// print status
$output->writeln("");
return;
return 0;
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/Phpmig/Console/Command/UpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
$version = $input->getArgument('version');

if (in_array($version, $versions)) {
return;
return 0;
}

if (!isset($migrations[$version])) {
return;
return 0;
}

$container = $this->getContainer();
$container['phpmig.migrator']->up($migrations[$version]);

return 0;
}
}

Expand Down

0 comments on commit a250ad4

Please sign in to comment.