Exemplo n.º 1
0
 /**
  * Wrap a method call in pushTime/popTime calls
  *
  * @param string method name
  * @param string string that identifies this call (comes in () after the call name in output)
  * @param array  array of arguments
  */
 private function wrapCall($name, $ident, array $args)
 {
     self::pushTime('', "-- {$name}({$ident})", '   -> ');
     call_user_func_array(array(Migration_Adapter::getAdapter(), $name), $args);
     // since this call likely made some change to the database, go ahead and rebuild
     // cached data
     // QFrame_Db_Table::scanDb();
     self::popTime();
 }
Exemplo n.º 2
0
 /**
  * Return the Migration_Adapter in use by this migration adapter 
  *
  * @return Migration_Adapter
  */
 public static final function getAdapter()
 {
     if (self::$adapter === null) {
         $zendAdapter = Zend_Db_Table_Abstract::getDefaultAdapter();
         $adapterClass = preg_replace('/^Zend_Db/', 'Migration', get_class($zendAdapter));
         if (!class_exists($adapterClass)) {
             throw new Exception('Missing migration adapter class for ' . get_class($zendAdapter));
         }
         $class = new ReflectionClass($adapterClass);
         self::$adapter = $class->newInstance($zendAdapter);
     }
     return self::$adapter;
 }
Exemplo n.º 3
0
    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
echo "\n";