From 8cd1cdff9fa30973fc379acdca27d9bf9f150794 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Tue, 30 Jun 2020 20:05:08 +0900 Subject: [PATCH] Fix install problems --- common/framework/db.php | 39 ++++++++++++++++------ common/framework/parsers/dbtable/table.php | 4 +-- modules/install/install.controller.php | 18 +++++----- modules/install/install.view.php | 16 +-------- modules/install/tpl/db_config.html | 20 ++--------- modules/install/tpl/js/install.js | 6 ---- 6 files changed, 44 insertions(+), 59 deletions(-) diff --git a/common/framework/db.php b/common/framework/db.php index b3f3cc42d..061af73ad 100644 --- a/common/framework/db.php +++ b/common/framework/db.php @@ -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; diff --git a/common/framework/parsers/dbtable/table.php b/common/framework/parsers/dbtable/table.php index 492fab9e5..b5f7cd4ad 100644 --- a/common/framework/parsers/dbtable/table.php +++ b/common/framework/parsers/dbtable/table.php @@ -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; } diff --git a/modules/install/install.controller.php b/modules/install/install.controller.php index 91f1106f5..6d62d5578 100644 --- a/modules/install/install.controller.php +++ b/modules/install/install.controller.php @@ -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 diff --git a/modules/install/install.view.php b/modules/install/install.view.php index f539ddcbb..854cff8f4 100644 --- a/modules/install/install.view.php +++ b/modules/install/install.view.php @@ -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'); } diff --git a/modules/install/tpl/db_config.html b/modules/install/tpl/db_config.html index 901e0e332..6ed0692f3 100644 --- a/modules/install/tpl/db_config.html +++ b/modules/install/tpl/db_config.html @@ -9,23 +9,7 @@ -
- -
- -
-
-

{$lang->db_desc[$val->db_type]}

+
@@ -48,7 +32,7 @@
-
+

{$lang->db_info_desc}
{$lang->db_prefix_desc} diff --git a/modules/install/tpl/js/install.js b/modules/install/tpl/js/install.js index 76943a8a7..ccf2387b9 100644 --- a/modules/install/tpl/js/install.js +++ b/modules/install/tpl/js/install.js @@ -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({