1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-06-28 20:45:00 +03:00

Доработка инсталлятора

This commit is contained in:
Mzhelskiy Maxim 2014-07-30 13:17:50 +07:00
parent e667db8f9e
commit ded28dc7a2
7 changed files with 102 additions and 52 deletions

View file

@ -36,6 +36,27 @@ class InstallStepInstallDb extends InstallStep {
* @return bool
*/
public function process() {
if (!$aRes=$this->processDbCheck()) {
return $aRes;
}
list($oDb,$sEngineDB)=$aRes;
/**
* Запускаем импорт дампов, сначала 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));
}
protected function processDbCheck() {
/**
* Коннект к серверу БД
*/
@ -102,20 +123,7 @@ class InstallStepInstallDb extends InstallStep {
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));
return array($oDb,$sEngineDB);
}
protected function getPathRootWeb() {

View file

@ -1,6 +1,6 @@
<?php
class InstallStepUpdateDb extends InstallStep {
class InstallStepUpdateDb extends InstallStepInstallDb {
protected function getTemplateName() {
/**
@ -9,32 +9,23 @@ class InstallStepUpdateDb extends InstallStep {
return 'steps/installDb.tpl.php';
}
/**
* Получаем данные для загрузки на форму
* Возможные источники: реквест, конфиг, дефолтные значения
*
* @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;
}
public function show() {
}
/**
* Обработка отправки формы
*
* @return bool
*/
public function process() {
if (!$aRes=$this->processDbCheck()) {
return $aRes;
}
list($oDb,$sEngineDB)=$aRes;
/**
* Запускаем импорт дампов, сначала GEO DB
*/
return true;
}
}

View file

@ -1,12 +0,0 @@
<?php
class InstallStepUpdateNote extends InstallStep {
public function show() {
}
public function process() {
return true;
}
}

View file

@ -0,0 +1,57 @@
<?php
class InstallStepUpdateVersion extends InstallStep {
protected $aVersionConvert=array(
'1.0.3','1.0.2','1.0.1'
);
public function show() {
$this->assign('from_version',InstallCore::getStoredData('update_from_version'));
$this->assign('convert_versions',$this->aVersionConvert);
}
public function process() {
/**
* Полчаем данные коннекта к БД из конфига
*/
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'));
}
$sVersion=(string)InstallCore::getRequest('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));
}
/**
* Конвертор версии 1.0.3 в 2.0.0
*
* @param $oDb
*/
public function convertFrom_1_0_3_to_2_0_0($oDb) {
}
}

View file

@ -108,6 +108,11 @@ return array(
'passwd' => 'Пароль должен быть от 3-х символов',
),
),
'updateVersion' => array(
'errors' => array(
'not_found_convert' => 'Для данной версии нет возможности обновления',
),
),
),
'config' => array(

View file

@ -11,8 +11,9 @@
<br/>
Ваша текущая версия:
<select>
<select name="from_version">
<option value=""></option>
<option>1.0.3</option>
<option>1.0.2</option>
<?php foreach($this->get('convert_versions') as $version) { ?>
<option <?php if ($this->get('from_version')==$version) { ?> selected="selected" <?php } ?> ><?php echo $version ?></option>
<?php } ?>
</select>

View file

@ -15,7 +15,7 @@ $aGroups=array(
),
'update'=>array(
'updateNote','checkRequirements','updateDb'=>array('hide_create_db'=>true),'updateComplete'
'checkRequirements','updateDb'=>array('hide_create_db'=>true),'updateVersion','updateComplete'
),
);