/** * Primary task entry point * * @param array $args The current supplied options. */ public function execute($args) { if (!$this->_adapter->supports_migrations()) { throw new Ruckusing_Exception("This database does not support migrations.", Ruckusing_Exception::MIGRATION_NOT_SUPPORTED); } $this->_task_args = $args; $this->_return .= "Started: " . date('Y-m-d g:ia T') . "\n\n"; $this->_return .= "[db:migrate]: \n"; try { // Check that the schema_version table exists, and if not, automatically create it $this->verify_environment(); $target_version = null; $style = STYLE_REGULAR; //did the user specify an explicit version? if (array_key_exists('version', $this->_task_args)) { $target_version = trim($this->_task_args['version']); } // did the user specify a relative offset, e.g. "-2" or "+3" ? if ($target_version !== null) { if (preg_match('/^([\\-\\+])(\\d+)$/', $target_version, $matches)) { if (count($matches) == 3) { $direction = $matches[1] == '-' ? 'down' : 'up'; $steps = intval($matches[2]); $style = STYLE_OFFSET; } } } //determine our direction and target version $current_version = $this->_migrator_util->get_max_version(); if ($style == STYLE_REGULAR) { if (is_null($target_version)) { $this->prepare_to_migrate($target_version, 'up'); } elseif ($current_version > $target_version) { $this->prepare_to_migrate($target_version, 'down'); } else { $this->prepare_to_migrate($target_version, 'up'); } } if ($style == STYLE_OFFSET) { $this->migrate_from_offset($steps, $current_version, $direction); } // Completed - display accumulated output if (!empty($output)) { $this->_return .= "\n\n"; } } catch (Ruckusing_Exception $ex) { if ($ex->getCode() == Ruckusing_Exception::MISSING_SCHEMA_INFO_TABLE) { $this->_return .= "\tSchema info table does not exist. I tried creating it but failed. Check permissions."; } else { throw $ex; } } $this->_return .= "\n\nFinished: " . date('Y-m-d g:ia T') . "\n\n"; return $this->_return; }