NOISSUE code rearrange on install.controller.php

This commit is contained in:
sol 2013-11-23 12:09:13 +09:00
parent bf0dd35f0a
commit 46e8b01f94

View file

@ -87,25 +87,22 @@ class installController extends install
// Get DB-related variables
$con_string = Context::gets('db_type','db_port','db_hostname','db_userid','db_password','db_database','db_table_prefix');
$db_info = new stdClass();
$db_info->master_db = get_object_vars($con_string);
$db_info->slave_db[] = get_object_vars($con_string);
if(!$db_info->default_url) $db_info->default_url = Context::getRequestUri();
$db_info->slave_db = array($db_info->master_db);
$db_info->default_url = Context::getRequestUri();
$db_info->lang_type = Context::getLangType();
$db_info->use_mobile_view = 'Y';
// Set DB type and information
Context::setDBInfo($db_info);
// Create DB Instance
$oDB = &DB::getInstance();
// Check if available to connect to the DB
$oDB = &DB::getInstance();
$output = $oDB->getError();
if(!$output->toBool()) return $output;
if(!$oDB->isConnected()) return $oDB->getError();
// When installing firebird DB, transaction will not be used
if($db_info->db_type != "firebird") $oDB->begin();
if($db_info->db_type != "firebird") $oDB->commit();
// Create a db temp config file
if(!$this->makeDBConfigFile()) return new Object(-1, 'msg_install_failed');
@ -144,7 +141,9 @@ class installController extends install
{
// Check if it is already installed
if(Context::isInstalled()) return new Object(-1, 'msg_already_installed');
// Assign a temporary administrator when installing
$logged_info = new stdClass();
$logged_info->is_admin = 'Y';
Context::set('logged_info', $logged_info);
@ -166,12 +165,12 @@ class installController extends install
$oDB = &DB::getInstance();
// Check if available to connect to the DB
if(!$oDB->isConnected()) return $oDB->getError();
// When installing firebire DB, transaction will not be used
if($db_info->db_type != "firebird") $oDB->begin();
// Install all the modules
$this->installDownloadedModule();
if($db_info->db_type != "firebird") $oDB->commit();
// Install all the modules
$oDB->begin();
$this->installDownloadedModule();
$oDB->commit();
// Create a config file
if(!$this->makeConfigFile()) return new Object(-1, 'msg_install_failed');
@ -208,18 +207,22 @@ class installController extends install
*/
function _makeDbInfoByInstallConfig()
{
$db_info->master_db['db_type'] = Context::get('db_type');
$db_info->master_db['db_port'] = Context::get('db_port');
$db_info->master_db['db_hostname'] = Context::get('db_hostname');
$db_info->master_db['db_userid'] = Context::get('db_userid');
$db_info->master_db['db_password'] = Context::get('db_password');
$db_info->master_db['db_database'] = Context::get('db_database');
$db_info->master_db['db_table_prefix'] = Context::get('db_table_prefix');
$db_info = new stdClass();
$db_info->master_db = array(
'db_type' => Context::get('db_type'),
'db_port' => Context::get('db_port'),
'db_hostname' => Context::get('db_hostname'),
'db_userid' => Context::get('db_userid'),
'db_password' => Context::get('db_password'),
'db_database' => Context::get('db_database'),
'db_table_prefix' => Context::get('db_table_prefix')
);
$db_info->slave_db = array($db_info->master_db);
$db_info->default_url = Context::getRequestUri();
$db_info->lang_type = Context::getLangType();
$db_info->use_rewrite = Context::get('use_rewrite');
$db_info->time_zone = Context::get('time_zone');
return $db_info;
}
@ -235,12 +238,12 @@ class installController extends install
if(!$ftp_info->ftp_host) $ftp_info->ftp_host = '127.0.0.1';
if(!$ftp_info->ftp_root_path) $ftp_info->ftp_root_path = '/';
$buff = '<?php if(!defined("__XE__")) exit();'."\n";
$buff = array('<?php if(!defined("__XE__")) exit();');
foreach($ftp_info as $key => $val)
{
$buff .= sprintf("\$ftp_info->%s = '%s';\n", $key, str_replace("'","\\'",$val));
$buff[] = sprintf("\$ftp_info->%s='%s';", $key, str_replace("'","\\'",$val));
}
$buff .= "?".">";
// If safe_mode
if(ini_get('safe_mode'))
{
@ -283,8 +286,7 @@ class installController extends install
$oFtp->ftp_quit();
}
$config_file = Context::getFTPConfigFile();
FileHandler::WriteFile($config_file, $buff);
FileHandler::WriteFile(Context::getFTPConfigFile(), join(PHP_EOL, $buff));
}
function procInstallCheckFtp()
@ -308,14 +310,13 @@ class installController extends install
{
require_once(_XE_PATH_.'libs/ftp.class.php');
$oFtp = new ftp();
if(!$oFtp->ftp_connect('localhost', $ftp_info->ftp_port)) return new Object(-1, sprintf(Context::getLang('msg_ftp_not_connected'), 'localhost'));
if(!$oFtp->ftp_connect('127.0.0.1', $ftp_info->ftp_port)) return new Object(-1, sprintf(Context::getLang('msg_ftp_not_connected'), 'localhost'));
if(!$oFtp->ftp_login($ftp_info->ftp_user, $ftp_info->ftp_password))
{
$oFtp->ftp_quit();
return new Object(-1,'msg_ftp_invalid_auth_info');
}
$oFtp->ftp_quit();
}
@ -359,7 +360,6 @@ class installController extends install
Context::set('install_enable', $install_enable);
Context::set('phpversion', PHP_VERSION);
return $install_enable;
}
@ -392,13 +392,10 @@ class installController extends install
if($start) $buff .= $str;
}
fclose($fp);
$ret = trim($buff);
FileHandler::removeFile(_XE_PATH_.$checkFilePath);
if( $ret == $checkString )
return true;
else
return false;
return (trim($buff) == $checkString);
}
/**
@ -515,34 +512,27 @@ class installController extends install
return new Object();
}
function _getDbConnText($key, $val, $with_array = false){
$buff = '';
if($with_array)
$buff .= "\$db_info->$key = array(";
else
$buff .= "\$db_info->$key = ";
if(!$with_array) $val = array($val);
function _getDbConnText($key, $val, $with_array = false)
{
$buff = array("\$db_info->$key = ");
if($with_array) $buff[] = "array(";
else $val = array($val);
foreach($val as $con_string)
{
$buff .= 'array(';
$buff[] = 'array(';
foreach($con_string as $k => $v)
{
if(in_array($k, array('resource', 'is_connected'))) continue;
if($k == 'db_table_prefix' && !empty($v))
{
if(substr($v,-1)!='_') $v .= '_';
}
$buff .= "'$k' => '$v',";
if($k == 'resource' || $k == 'is_connected') continue;
if($k == 'db_table_prefix' && !empty($v) && substr($v,-1)!='_') $v .= '_';
$buff[] = "'$k' => '$v',";
}
$buff = substr($buff, 0, -1);
$buff .= '),';
$buff[] = '),';
}
$buff = substr($buff, 0, -1);
if($with_array)
$buff .= ');' . PHP_EOL;
else
$buff .= ';' . PHP_EOL;
return $buff;
if($with_array) $buff[] = ')';
return join(PHP_EOL, $buff) . ';' . PHP_EOL;
}
function _getDBConfigFileContents($db_info)
@ -620,7 +610,6 @@ class installController extends install
{
$buff .= sprintf("\$db_info->%s = '%s';\n", $key, str_replace("'","\\'",$val));
}
$buff .= "?>";
FileHandler::writeFile($etc_tmp_config_file, $buff);