2014-07-28 09:23:41 +03:00
|
|
|
<?php
|
|
|
|
|
2014-07-30 08:32:30 +03:00
|
|
|
class InstallStepInstallDb extends InstallStep {
|
2014-07-28 09:23:41 +03:00
|
|
|
|
|
|
|
protected $sConfigPath;
|
|
|
|
|
|
|
|
public function init() {
|
|
|
|
$this->sConfigPath=dirname(INSTALL_DIR).DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.local.php';
|
|
|
|
InstallConfig::$sFileConfig=$this->sConfigPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Получаем данные для загрузки на форму
|
|
|
|
* Возможные источники: реквест, конфиг, дефолтные значения
|
|
|
|
*
|
|
|
|
* @param $sName
|
|
|
|
* @param null $mDefault
|
|
|
|
* @param bool $bUseHtmlspecialchars
|
|
|
|
*
|
|
|
|
* @return mixed|null|string
|
|
|
|
*/
|
|
|
|
public function getValue($sName,$mDefault=null,$bUseHtmlspecialchars=true) {
|
|
|
|
$mResult=null;
|
|
|
|
$sNameRequest=str_replace('.','_',$sName);
|
|
|
|
if (isset($_REQUEST[$sNameRequest])) {
|
|
|
|
$mResult=$_REQUEST[$sNameRequest];
|
|
|
|
} else {
|
|
|
|
$mResult=InstallConfig::get($sName,$mDefault);
|
|
|
|
}
|
|
|
|
return $bUseHtmlspecialchars ? htmlspecialchars($mResult) : $mResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Обработка отправки формы
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function process() {
|
|
|
|
/**
|
|
|
|
* Коннект к серверу БД
|
|
|
|
*/
|
|
|
|
if (!$oDb=$this->getDBConnection(InstallCore::getRequest('db.params.host'),InstallCore::getRequest('db.params.port'),InstallCore::getRequest('db.params.user'),InstallCore::getRequest('db.params.pass'))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Выбор БД
|
|
|
|
*/
|
|
|
|
$sNameDb=InstallCore::getRequest('db.params.dbname');
|
|
|
|
if (!InstallCore::getRequest('db_create')) {
|
|
|
|
if (!@mysqli_select_db($oDb,$sNameDb)) {
|
2014-07-30 08:32:30 +03:00
|
|
|
return $this->addError(InstallCore::getLang('steps.installDb.errors.db_not_found'));
|
2014-07-28 09:23:41 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/**
|
|
|
|
* Пытаемся создать БД
|
|
|
|
*/
|
|
|
|
@mysqli_query($oDb,"CREATE DATABASE $sNameDb");
|
|
|
|
if (!@mysqli_select_db($oDb,$sNameDb)) {
|
2014-07-30 08:32:30 +03:00
|
|
|
return $this->addError(InstallCore::getLang('steps.installDb.errors.db_not_create'));
|
2014-07-28 09:23:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Проверяем корректность префикса таблиц
|
|
|
|
*/
|
|
|
|
if (!preg_match('#^[a-z0-9\_]*$#i',InstallCore::getRequest('db.table.prefix'))) {
|
2014-07-30 08:32:30 +03:00
|
|
|
return $this->addError(InstallCore::getLang('steps.installDb.errors.db_table_prefix'));
|
2014-07-28 09:23:41 +03:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Определяем поддержку 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-07-28 10:43:39 +03:00
|
|
|
|
|
|
|
$sPathRootWeb=$this->getPathRootWeb();
|
|
|
|
$aDirs=array();
|
|
|
|
$sDirs=trim(str_replace('http://'.$_SERVER['HTTP_HOST'],'',$sPathRootWeb),'/');
|
|
|
|
if ($sDirs!='') {
|
|
|
|
$aDirs=explode('/',$sDirs);
|
|
|
|
}
|
|
|
|
|
2014-07-28 09:23:41 +03:00
|
|
|
/**
|
|
|
|
* Прописываем параметры в конфиг
|
|
|
|
*/
|
|
|
|
$aSave=array(
|
|
|
|
'db.params.host' => InstallCore::getRequest('db.params.host'),
|
|
|
|
'db.params.port' => InstallCore::getRequest('db.params.port'),
|
|
|
|
'db.params.dbname' => InstallCore::getRequest('db.params.dbname'),
|
|
|
|
'db.params.user' => InstallCore::getRequest('db.params.user'),
|
|
|
|
'db.params.pass' => InstallCore::getRequest('db.params.pass'),
|
|
|
|
'db.table.prefix' => InstallCore::getRequest('db.table.prefix'),
|
|
|
|
'db.tables.engine' => $sEngineDB,
|
2014-07-28 10:43:39 +03:00
|
|
|
'path.root.web' => $sPathRootWeb,
|
|
|
|
'path.offset_request_url' => count($aDirs),
|
2014-07-28 09:23:41 +03:00
|
|
|
);
|
|
|
|
if (!InstallConfig::save($aSave)) {
|
|
|
|
return $this->addError(InstallConfig::$sLastError);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Запускаем импорт дампов, сначала GEO DB
|
|
|
|
*/
|
|
|
|
list($bResult,$aErrors)=array_values($this->importDumpDB($oDb,InstallCore::getDataFilePath('sql/geo.sql'),array('engine'=>$sEngineDB,'prefix'=>InstallCore::getRequest('db.table.prefix'),'check_table'=>'geo_city')));
|
|
|
|
if ($bResult) {
|
|
|
|
/**
|
|
|
|
* Запускаем основной дамп
|
|
|
|
*/
|
|
|
|
list($bResult,$aErrors)=array_values($this->importDumpDB($oDb,InstallCore::getDataFilePath('sql/dump.sql'),array('engine'=>$sEngineDB,'prefix'=>InstallCore::getRequest('db.table.prefix'),'check_table'=>'topic')));
|
|
|
|
if ($bResult) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->addError(join('<br/>',$aErrors));
|
|
|
|
}
|
|
|
|
|
2014-07-28 10:43:39 +03:00
|
|
|
protected function getPathRootWeb() {
|
|
|
|
$sPath=rtrim('http://'.$_SERVER['HTTP_HOST'],'/').str_replace('/install/index.php','',$_SERVER['PHP_SELF']);
|
|
|
|
return preg_replace('#\/application$#','',$sPath);
|
|
|
|
}
|
2014-07-28 09:23:41 +03:00
|
|
|
}
|