/** * 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; }