Skip to content

Instantly share code, notes, and snippets.

@f3ath
Last active October 15, 2016 06:40
Show Gist options
  • Save f3ath/de79e5ebd534470cdc92db6bfc00e24b to your computer and use it in GitHub Desktop.
Save f3ath/de79e5ebd534470cdc92db6bfc00e24b to your computer and use it in GitHub Desktop.
<?php
/**
* Returns sorted array of all versions reachable from $version
* @param string $version
* @return string[]
*/
public function getReachableVersions($version)
{
$migrations = $this->migration_manager->getMigrations();
$versions = array_keys($migrations);
$index = array_search($version, $versions);
if ($index === false) {
throw new OutOfBoundsException("Version not found: $version");
}
$upgrades = array_slice($versions, $index + 1);
$downgrades = [];
for ($min = $index; $min > 0 && $migrations[$versions[$min]]->canRollback(); $min--) {
$downgrades[] = $versions[$min - 1];
}
return [$downgrades, $upgrades];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment