Last active
October 15, 2016 06:40
-
-
Save f3ath/de79e5ebd534470cdc92db6bfc00e24b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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