public function process() { set_time_limit(0); /** * Коннект к серверу БД */ if (!($oDb = $this->getDBConnection(InstallConfig::get('db.params.host'), InstallConfig::get('db.params.port'), InstallConfig::get('db.params.user'), InstallConfig::get('db.params.pass'), true))) { return false; } /** * Выбираем БД */ if (!@mysqli_select_db($oDb, InstallConfig::get('db.params.dbname'))) { return $this->addError(InstallCore::getLang('db.errors.db_query')); } $this->setDbParams(array('prefix' => InstallConfig::get('db.table.prefix'), 'engine' => InstallConfig::get('db.tables.engine'))); $sVersion = InstallCore::getRequestStr('from_version'); /** * Проверяем наличие конвертора * Конвертор представляет собой отдельный метод вида converFrom_X1_Y1_Z1_to_X2_Y2_Z2 */ $sMethod = 'convertFrom_' . str_replace('.', '_', $sVersion) . '_to_' . str_replace('.', '_', VERSION); if (!method_exists($this, $sMethod)) { return $this->addError(InstallCore::getLang('steps.updateVersion.errors.not_found_convert')); } InstallCore::setStoredData('update_from_version', $sVersion); /** * Запускаем конвертор */ return call_user_func_array(array($this, $sMethod), array($oDb)); }
/** * Обработка отправки формы * * @return bool */ public function process() { /** * Проверяем корректность емайла */ $sMail = InstallCore::getRequestStr('admin_mail'); if (!preg_match("/^[\\da-z\\_\\-\\.\\+]+@[\\da-z_\\-\\.]+\\.[a-z]{2,5}\$/i", $sMail)) { return $this->addError(InstallCore::getLang('steps.installAdmin.errors.mail')); } /** * Проверяем корректность пароль */ $sPasswd = InstallCore::getRequestStr('admin_passwd'); if (mb_strlen($sPasswd, 'UTF-8') < 3) { return $this->addError(InstallCore::getLang('steps.installAdmin.errors.passwd')); } /** * Получаем данные коннекта к БД из конфига */ InstallConfig::$sFileConfig = dirname(INSTALL_DIR) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.local.php'; /** * Коннект к серверу БД */ if (!($oDb = $this->getDBConnection(InstallConfig::get('db.params.host'), InstallConfig::get('db.params.port'), InstallConfig::get('db.params.user'), InstallConfig::get('db.params.pass')))) { return false; } /** * Выбираем БД */ if (!@mysqli_select_db($oDb, InstallConfig::get('db.params.dbname'))) { return $this->addError(InstallCore::getLang('db.errors.db_query')); } /** * Обновляем пользователя */ $sPrefix = InstallConfig::get('db.table.prefix'); $sQuery = "\n\t\t\tUPDATE `{$sPrefix}user`\n\t\t\tSET\n\t\t\t\t`user_mail`\t = '{$sMail}',\n\t\t\t\t`user_admin`\t = '1',\n\t\t\t\t`user_password` = '" . md5($sPasswd) . "'\n\t\t\tWHERE `user_id` = 1"; if (!mysqli_query($oDb, $sQuery)) { return $this->addError(InstallCore::getLang('db.errors.db_query')); } return true; }
<p><label for=""><?php echo $this->lang('steps.installAdmin.form.mail.title'); ?> </label> <input type="text" name="admin_mail" value="<?php echo htmlspecialchars(InstallCore::getRequestStr('admin_mail')); ?> "></p> <p><label for=""><?php echo $this->lang('steps.installAdmin.form.passwd.title'); ?> </label> <input type="password" name="admin_passwd" value="<?php echo htmlspecialchars(InstallCore::getRequestStr('admin_passwd')); ?> "></p>
protected function processDbCheck() { /** * Коннект к серверу БД */ if (!($oDb = $this->getDBConnection(InstallCore::getRequestStr('db.params.host'), InstallCore::getRequestStr('db.params.port'), InstallCore::getRequestStr('db.params.user'), InstallCore::getRequestStr('db.params.pass')))) { return false; } /** * Выбор БД */ $sNameDb = InstallCore::getRequestStr('db.params.dbname'); if (!InstallCore::getRequest('db_create')) { if (!@mysqli_select_db($oDb, $sNameDb)) { return $this->addError(InstallCore::getLang('steps.installDb.errors.db_not_found')); } } else { /** * Пытаемся создать БД */ @mysqli_query($oDb, "CREATE DATABASE IF NOT EXISTS `{$sNameDb}` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci"); if (!@mysqli_select_db($oDb, $sNameDb)) { return $this->addError(InstallCore::getLang('steps.installDb.errors.db_not_create')); } } /** * Проверяем корректность префикса таблиц */ if (!preg_match('#^[a-z0-9\\_]*$#i', InstallCore::getRequestStr('db.table.prefix'))) { return $this->addError(InstallCore::getLang('steps.installDb.errors.db_table_prefix')); } /** * Определяем поддержку InnoDB */ $sEngineDB = 'MyISAM'; if ($aRes = @mysqli_query($oDb, 'SHOW ENGINES')) { while ($aRow = mysqli_fetch_assoc($aRes)) { if (strtoupper($aRow['Engine']) == 'INNODB' and in_array(strtoupper($aRow['Support']), array('DEFAULT', 'YES'))) { $sEngineDB = 'InnoDB'; break; } } } $sPathRootWeb = $this->getPathRootWeb(); $aDirs = array(); $sDirs = trim(str_replace('http://' . $_SERVER['HTTP_HOST'], '', $sPathRootWeb), '/'); if ($sDirs != '') { $aDirs = explode('/', $sDirs); } /** * Прописываем параметры в конфиг */ $aSave = array('db.params.host' => InstallCore::getRequestStr('db.params.host'), 'db.params.port' => InstallCore::getRequestStr('db.params.port'), 'db.params.dbname' => InstallCore::getRequestStr('db.params.dbname'), 'db.params.user' => InstallCore::getRequestStr('db.params.user'), 'db.params.pass' => InstallCore::getRequestStr('db.params.pass'), 'db.table.prefix' => InstallCore::getRequestStr('db.table.prefix'), 'db.tables.engine' => $sEngineDB, 'path.root.web' => $sPathRootWeb, 'path.offset_request_url' => count($aDirs)); if (!InstallConfig::save($aSave)) { return $this->addError(InstallConfig::$sLastError); } return array($oDb, $sEngineDB); }