public function init() { // подключаем конфигурацию $this->config = (require MUSHROOM_DIR_APP_CONFIG . '/config.php'); // настраиваем алиасы классов foreach ($this->config['classAliases'] as $serviceName => $className) { class_alias($className, $serviceName); } // подключаем СУБД Event::trigger('onBeforeDatabaseInit', $app); if ($this->config['database'] && $this->config['database']['type']) { $this->database = DatabaseManager::get($this->config['database']); QueryBuilder::setup($this->database); // QueryBuilder::setDatabaseType($this->config['database']['type']); // QueryBuilder::setEncoding($this->database->getEncoding(), $this->database->getCollate()); // QueryBuilder::setDatabaseManager($this->database); } Event::trigger('onAfterDatabaseInit', $app); }
/** * Console application's method for rolling back $maxSteps unrolled migrations. * Method rolls back 1 unrolled migration if $maxSteps is not defined * @throws Exception * @param int $maxSteps * @return void */ public static function rollback($maxSteps = 1) { if (!static::installed()) { throw new Exception('migrations table is not installed'); } $sql = QueryBuilder::select()->from(static::$tableName)->where('active', '=', '1')->orderBy(array('timestamp' => 'DESC')); if ($maxSteps) { $sql->limit(intval($maxSteps)); } $rs = $sql->exec(); while ($migration = $rs->fetch()) { $path = MUSHROOM_DIR_APP_MIGRATIONS . '/' . $migration['className'] . '.php'; if (is_file($path)) { include $path; $instance = new $migration['className'](); $instance->down(); QueryBuilder::update(static::$tableName, array('active' => 0))->where('id', '=', $migration['id'])->exec(); echo "Migration '{$migration['name']}' uninstalled\n"; } else { QueryBuilder::delete(static::$tableName)->where('id', '=', $migration['id'])->exec(); echo "Migration '{$migration['name']}' not uninstalled (file '{$path}' not found)\n"; } } }
/** * Starts ALTER TABLE query * @return QueryBuilder */ protected function alter() { return QueryBuilder::alterTable($this->tableName); }