Fix install problems

This commit is contained in:
Kijin Sung 2020-06-30 20:05:08 +09:00
parent 0f561b3814
commit 8cd1cdff9f
6 changed files with 44 additions and 59 deletions

View file

@ -69,15 +69,21 @@ class DB
return self::$_instances[$type];
}
// Check if configuration exists for the selected DB type.
$config = Config::get('db.' . $type) ?: array();
if (!count($config))
// Create an instance with the appropriate configuration.
if ($config = Config::get('db'))
{
throw new Exceptions\DBError('DB type \'' . $type . '\' is not configured.');
$typeconfig = isset($config[$type]) ? $config[$type] : [];
if (!count($typeconfig))
{
throw new Exceptions\DBError('DB type \'' . $type . '\' is not configured.');
}
return self::$_instances[$type] = new self($type, $typeconfig);
}
else
{
return new self($type, []);
}
// Create an instance and return it.
return self::$_instances[$type] = new self($type, $config);
}
/**
@ -93,6 +99,10 @@ class DB
$this->_prefix = $config['prefix'] ?: $this->_prefix;
$this->_charset = $config['charset'] ?: $this->_charset;
$this->_engine = $config['engine'] ?: $this->_engine;
if (!count($config))
{
return;
}
// Connect to the DB.
$dsn = 'mysql:host=' . $config['host'];
@ -212,6 +222,10 @@ class DB
{
return $this->setError(-1, 'Invalid query arguments.');
}
if (!$this->_handle)
{
return $this->setError(-1, 'DB is not configured.');
}
// Force the column list to a numerical array.
$column_list = is_array($column_list) ? array_values($column_list) : array();
@ -427,7 +441,7 @@ class DB
* @param string $query_string
* @return Helpers\DBStmtHelper
*/
public function _query(string $query_string)
public function _query($query_string)
{
$this->_last_stmt = $this->_handle->query($query_string);
return $this->_last_stmt;
@ -441,10 +455,15 @@ class DB
*
* @param \PDOStatement $stmt
* @param int $last_index
* @return array|object
* @return mixed
*/
public function _fetch(\PDOStatement $stmt, int $last_index = 0)
public function _fetch($stmt, $last_index = 0)
{
if (!($stmt instanceof \PDOStatement))
{
return null;
}
$result = array();
$index = $last_index;
$step = $last_index !== 0 ? -1 : 1;

View file

@ -82,9 +82,9 @@ class Table
foreach ($index->columns as $column_name => $prefix_size)
{
$column_info = $this->columns[$column_name];
$current_size = isset($adjusted_sizes[$column->name]) ? $adjusted_sizes[$column->name] : $column->size;
$current_size = isset($adjusted_sizes[$column_name]) ? $adjusted_sizes[$column_name] : $column_info->size;
$max_size = $column_info->utf8mb4 ? 191 : 255;
if (preg_match('/char/i', $column->type) && $current_size > $max_size)
if (preg_match('/char/i', $column_info->type) && $current_size > $max_size)
{
$prefix_size = $max_size;
}

View file

@ -40,7 +40,7 @@ class installController extends install
'user' => $config->db_user,
'pass' => $config->db_pass,
'database' => $config->db_database,
'prefix' => rtrim($config->db_prefix, '_') . '_',
'prefix' => $config->db_prefix ? (rtrim($config->db_prefix, '_') . '_') : '',
));
// Check connection to the DB.
@ -107,7 +107,7 @@ class installController extends install
if ($install_config)
{
$install_config = (array)$install_config;
$config['db']['master']['type'] = str_replace('_innodb', '', $install_config['db_type']);
$config['db']['master']['type'] = 'mysql';
$config['db']['master']['host'] = $install_config['db_hostname'];
$config['db']['master']['port'] = $install_config['db_port'];
$config['db']['master']['user'] = $install_config['db_userid'];
@ -115,7 +115,7 @@ class installController extends install
$config['db']['master']['database'] = $install_config['db_database'];
$config['db']['master']['prefix'] = $install_config['db_table_prefix'];
$config['db']['master']['charset'] = $install_config['db_charset'];
$config['db']['master']['engine'] = strpos($install_config['db_type'], 'innodb') !== false ? 'innodb' : (strpos($install_config['db_type'], 'mysql') !== false ? 'myisam' : null);
$config['db']['master']['engine'] = strpos($install_config['db_type'], 'innodb') !== false ? 'innodb' : 'myisam';
$config['use_rewrite'] = $install_config['use_rewrite'] === 'Y' ? true : false;
$config['url']['ssl'] = $install_config['use_ssl'] ?: 'none';
$time_zone = $install_config['time_zone'];
@ -127,7 +127,7 @@ class installController extends install
}
else
{
$config['db']['master']['type'] = str_replace('_innodb', '', $_SESSION['db_config']->db_type);
$config['db']['master']['type'] = 'mysql';
$config['db']['master']['host'] = $_SESSION['db_config']->db_host;
$config['db']['master']['port'] = $_SESSION['db_config']->db_port;
$config['db']['master']['user'] = $_SESSION['db_config']->db_user;
@ -135,7 +135,7 @@ class installController extends install
$config['db']['master']['database'] = $_SESSION['db_config']->db_database;
$config['db']['master']['prefix'] = $_SESSION['db_config']->db_prefix;
$config['db']['master']['charset'] = $_SESSION['db_config']->db_charset;
$config['db']['master']['engine'] = strpos($_SESSION['db_config']->db_type, 'innodb') !== false ? 'innodb' : (strpos($_SESSION['db_config']->db_type, 'mysql') !== false ? 'myisam' : null);
$config['db']['master']['engine'] = strpos($_SESSION['db_config']->db_type, 'innodb') !== false ? 'innodb' : 'myisam';
$config['use_rewrite'] = $_SESSION['use_rewrite'] === 'Y' ? true : false;
$config['url']['ssl'] = Context::get('use_ssl') ?: 'none';
$time_zone = Context::get('time_zone');
@ -227,6 +227,7 @@ class installController extends install
catch(Exception $e)
{
$oDB->rollback();
var_dump($e);exit;
throw new Rhymix\Framework\Exception($e->getMessage());
}
@ -243,7 +244,6 @@ class installController extends install
}
// Apply site lock.
if (Context::get('use_sitelock') === 'Y')
{
$user_ip_range = getView('install')->detectUserIPRange();
@ -286,7 +286,7 @@ class installController extends install
}
// Check DB
if(DB::getEnableList())
if(extension_loaded('pdo_mysql'))
{
$checklist['db_support'] = true;
}
@ -523,10 +523,12 @@ class installController extends install
{
$file = trim($schema_files[$i]);
if(!$file || substr($file,-4)!='.xml') continue;
$table_name = substr(basename($file), 0, -4);
if($oDB->isTableExists($table_name)) continue;
$output = $oDB->createTableByXmlFile($file);
if($output === false)
{
throw new Exception(lang('msg_create_table_failed') . ': ' . $oDB->getError()->getMessage());
throw new Exception(lang('msg_create_table_failed') . ': ' . basename($file) . ': ' . $oDB->getError()->getMessage());
}
}
// Create a table and module instance and then execute install() method

View file

@ -101,21 +101,7 @@ class installView extends install
Context::set('use_rewrite', $_SESSION['use_rewrite'] = 'Y');
}
$defaultDatabase = 'mysqli';
$disableList = DB::getDisableList();
if(is_array($disableList))
{
foreach($disableList as $key => $value)
{
if($value->db_type == $defaultDatabase)
{
$defaultDatabase = 'mysql';
break;
}
}
}
Context::set('defaultDatabase', $defaultDatabase);
Context::set('error_return_url', getNotEncodedUrl('', 'act', Context::get('act'), 'db_type', Context::get('db_type')));
Context::set('error_return_url', getNotEncodedUrl('', 'act', Context::get('act')));
$this->setTemplateFile('db_config');
}

View file

@ -9,23 +9,7 @@
<input type="hidden" value="{$error_return_url}" name="error_return_url">
<input type="hidden" name="module" value="{$module}" />
<input type="hidden" name="act" value="procDBConfig" />
<div class="x_control-group">
<label for="db_type" class="x_control-label">{$lang->db_type}</label>
<div class="x_controls">
<select id="db_type" name="db_type">
<block loop="DB::getEnableList() => $key,$val">
<option value="{$val->db_type}" selected="selected"|cond="$val->db_type==$defaultDatabase" />
{$val->db_type}
<block cond="$val->db_type == $defaultDatabase">({$lang->cmd_recommended})</block>
</option>
</block>
<block loop="DB::getDisableList() => $key,$val">
<option value="{$val->db_type}" disabled="disabled" />{$val->db_type} ({$lang->can_use_when_installed})</option>
</block>
</select>
</div>
</div>
<p loop="DB::getEnableList() => $key,$val" class="install_help db_type db_type_{$val->db_type}">{$lang->db_desc[$val->db_type]}</p>
<input type="hidden" name="db_type" value="mysql" />
<div class="x_control-group">
<label for="db_host" class="x_control-label">{$lang->db_hostname}</label>
<div class="x_controls"><input name="db_host" value="localhost" type="text" id="db_host" required /></div>
@ -48,7 +32,7 @@
</div>
<div class="x_control-group">
<label for="db_prefix" class="x_control-label">{$lang->db_table_prefix}</label>
<div class="x_controls"><input name="db_prefix" type="text" id="db_prefix" value="rx" required /></div>
<div class="x_controls"><input name="db_prefix" type="text" id="db_prefix" value="rx_" /></div>
</div>
<p class="install_help">
{$lang->db_info_desc}<br />{$lang->db_prefix_desc}

View file

@ -1,11 +1,5 @@
jQuery(function($){
$('.focus').focus();
if($("#db_type").size()) {
$("#db_type").click(function() {
$("p.db_type").hide();
$("p.db_type_" + $(this).val()).show();
}).triggerHandler("click");
}
if($("#mod_rewrite_checking").size()) {
var checking = $("#mod_rewrite_checking");
$.ajax({