Beispiel #1
0
} else {
    krsort($migrations);
}
// Sort migrations that need to run and run 'em
foreach ($migrations as $version => $migration) {
    // continue to the next iteration if we are already past this version
    $current = Migration_Adapter::getAdapter()->getSchemaVersion();
    if ($migrateUp && $version <= $current || !$migrateUp && $version > $current) {
        continue;
    }
    // break from the loop if we have reached the desired version
    if ($migrateUp && $version > $target || !$migrateUp && $version <= $target) {
        break;
    }
    // print a message indicating that we are starting a migration
    Migration::pushTime("== {$version} {$migration}: migrat", 'ing ', 'ed ', true, '=', 80);
    // create an instance of the migration class and call it's up (or down) method
    $class = new ReflectionClass($migration);
    $instance = $class->newInstance();
    if ($migrateUp) {
        Migration_Adapter::getAdapter()->up($instance, $version);
    } else {
        Migration_Adapter::getAdapter()->down($instance, $version);
    }
    // print a message indicating that we are down with this migration
    Migration::popTime();
}
// If we have gotten to this point make sure the schema version is set to the target (especially
// important for migrating down since we never actually run the target migration)
Migration_Adapter::getAdapter()->setSchemaVersion($target);
// Print a final newline