Skip to content

Commit 7670743

Browse files
committed
Merge pull request #12 from stefk/master
Avoid exception if target bundle has no migration directory
2 parents 039acb6 + d008d6c commit 7670743

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

Command/VersionCommand.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,16 @@ protected function execute(InputInterface $input, OutputInterface $output)
3636
{
3737
$status = $this->getManager($output)->getBundleStatus($this->getTargetBundle($input));
3838

39-
foreach ($status[Migrator::STATUS_AVAILABLE] as $version) {
40-
$output->writeln(
41-
$version === $status[Migrator::STATUS_CURRENT] ?
42-
" * {$version} (current)" :
43-
" {$version}"
44-
);
39+
if (count($status[Migrator::STATUS_AVAILABLE]) > 0) {
40+
foreach ($status[Migrator::STATUS_AVAILABLE] as $version) {
41+
$output->writeln(
42+
$version === $status[Migrator::STATUS_CURRENT] ?
43+
" * {$version} (current)" :
44+
" {$version}"
45+
);
46+
}
47+
} else {
48+
$output->writeln('No migration is available for this bundle.');
4549
}
4650
}
4751
}

Migrator/Migrator.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,18 @@ public function getCurrentVersion(Bundle $bundle)
6565
public function getMigrationStatus(Bundle $bundle)
6666
{
6767
$config = $this->getConfiguration($bundle);
68-
$availableVersions = $config->getAvailableVersions();
69-
array_unshift($availableVersions, '0');
68+
69+
if (is_dir($config->getMigrationsDirectory())) {
70+
$currentVersion = $config->getCurrentVersion();
71+
$availableVersions = $config->getAvailableVersions();
72+
array_unshift($availableVersions, '0');
73+
} else {
74+
$currentVersion = '0';
75+
$availableVersions = [];
76+
}
7077

7178
return array(
72-
self::STATUS_CURRENT => $config->getCurrentVersion(),
79+
self::STATUS_CURRENT => $currentVersion,
7380
self::STATUS_AVAILABLE => $availableVersions
7481
);
7582
}

0 commit comments

Comments
 (0)