コード例 #1
0
 /**
  * Run migrations
  *
  * @param array $migrations nigrations to run
  * @param $string $target_method direction to migrate to 'up'/'down'
  * @param string $destination version to migrate to
  *
  * @return array
  */
 private function run_migrations($migrations, $target_method, $destination)
 {
     $last_version = -1;
     foreach ($migrations as $file) {
         $full_path = $this->_migratorDirs[$file['module']] . DIRECTORY_SEPARATOR . $file['file'];
         if (is_file($full_path) && is_readable($full_path)) {
             require_once $full_path;
             $klass = Ruckusing_Util_Naming::class_from_migration_file($file['file']);
             $obj = new $klass($this->_adapter);
             $start = $this->start_timer();
             try {
                 //start transaction
                 $this->_adapter->start_transaction();
                 $result = $obj->{$target_method}();
                 //successfully ran migration, update our version and commit
                 $this->_migrator_util->resolve_current_version($file['version'], $target_method);
                 $this->_adapter->commit_transaction();
             } catch (Ruckusing_Exception $e) {
                 $this->_adapter->rollback_transaction();
                 //wrap the caught exception in our own
                 throw new Ruckusing_Exception(sprintf("%s - %s", $file['class'], $e->getMessage()), Ruckusing_Exception::MIGRATION_FAILED);
             }
             $end = $this->end_timer();
             $diff = $this->diff_timer($start, $end);
             $this->_return .= sprintf("========= %s ======== (%.2f)\n", $file['class'], $diff);
             $last_version = $file['version'];
             $exec = true;
         }
     }
     //update the schema info
     $result = array('last_version' => $last_version);
     return $result;
 }
 /**
  * test resolve current version going down
  */
 public function test_resolve_current_version_going_down()
 {
     $this->clear_dummy_data();
     $this->insert_dummy_version_data(array(1, 2, 3));
     $migrator_util = new Ruckusing_Util_Migrator($this->adapter);
     $migrator_util->resolve_current_version(3, 'down');
     $executed = $migrator_util->get_executed_migrations();
     $this->assertEquals(false, in_array(3, $executed));
     $this->assertEquals(true, in_array(1, $executed));
     $this->assertEquals(true, in_array(2, $executed));
 }