Skip to content

Commit

Permalink
Merge pull request #12 from stefk/master
Browse files Browse the repository at this point in the history
Avoid exception if target bundle has no migration directory
  • Loading branch information
ngodfraind committed Jan 22, 2016
2 parents 039acb6 + d008d6c commit 7670743
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
16 changes: 10 additions & 6 deletions Command/VersionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$status = $this->getManager($output)->getBundleStatus($this->getTargetBundle($input));

foreach ($status[Migrator::STATUS_AVAILABLE] as $version) {
$output->writeln(
$version === $status[Migrator::STATUS_CURRENT] ?
" * {$version} (current)" :
" {$version}"
);
if (count($status[Migrator::STATUS_AVAILABLE]) > 0) {
foreach ($status[Migrator::STATUS_AVAILABLE] as $version) {
$output->writeln(
$version === $status[Migrator::STATUS_CURRENT] ?
" * {$version} (current)" :
" {$version}"
);
}
} else {
$output->writeln('No migration is available for this bundle.');
}
}
}
13 changes: 10 additions & 3 deletions Migrator/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,18 @@ public function getCurrentVersion(Bundle $bundle)
public function getMigrationStatus(Bundle $bundle)
{
$config = $this->getConfiguration($bundle);
$availableVersions = $config->getAvailableVersions();
array_unshift($availableVersions, '0');

if (is_dir($config->getMigrationsDirectory())) {
$currentVersion = $config->getCurrentVersion();
$availableVersions = $config->getAvailableVersions();
array_unshift($availableVersions, '0');
} else {
$currentVersion = '0';
$availableVersions = [];
}

return array(
self::STATUS_CURRENT => $config->getCurrentVersion(),
self::STATUS_CURRENT => $currentVersion,
self::STATUS_AVAILABLE => $availableVersions
);
}
Expand Down

0 comments on commit 7670743

Please sign in to comment.