From 14b61d77101f89fad9351165201bc874b5511bf8 Mon Sep 17 00:00:00 2001 From: jdarwood007 Date: Sun, 5 Nov 2023 07:47:07 -0800 Subject: [PATCH 01/11] Fix the upgrader not finding the proper db type --- Sources/Db/DatabaseApi.php | 41 ++++++++++++++++++++++---------------- other/upgrade.php | 4 ++-- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/Sources/Db/DatabaseApi.php b/Sources/Db/DatabaseApi.php index 53fc3504b4..224608622c 100644 --- a/Sources/Db/DatabaseApi.php +++ b/Sources/Db/DatabaseApi.php @@ -326,7 +326,27 @@ final public static function load(array $options = []) } // Figure out what type of database we are using. - switch (!empty(Config::$db_type) ? strtolower(Config::$db_type) : 'mysql') { + $class = self::type(!empty(Config::$db_type) ? strtolower(Config::$db_type) : 'mysql'); + + if (!class_exists(__NAMESPACE__ . '\\APIs\\' . $class)) { + ErrorHandler::displayDbError(); + } + + $class = __NAMESPACE__ . '\\APIs\\' . $class; + self::$db = new $class($options); + + // Double check that we found what we expected. + if (!(self::$db instanceof DatabaseApi)) { + unset(self::$db); + ErrorHandler::displayDbError(); + } + + return self::$db; + } + + public static function type($db_type) + { + switch (strtolower($db_type)) { // PostgreSQL is known by many names. case 'postgresql': case 'postgres': @@ -335,14 +355,14 @@ final public static function load(array $options = []) $class = POSTGRE_TITLE; break; - // MySQL and its forks. + // MySQL and its forks. case 'mysql': case 'mariadb': case 'percona': $class = MYSQL_TITLE; break; - // Something else? + // Something else? default: $class = ucwords(Config::$db_type); @@ -354,20 +374,7 @@ final public static function load(array $options = []) break; } - if (!class_exists(__NAMESPACE__ . '\\APIs\\' . $class)) { - ErrorHandler::displayDbError(); - } - - $class = __NAMESPACE__ . '\\APIs\\' . $class; - self::$db = new $class($options); - - // Double check that we found what we expected. - if (!(self::$db instanceof DatabaseApi)) { - unset(self::$db); - ErrorHandler::displayDbError(); - } - - return self::$db; + return $class; } /** diff --git a/other/upgrade.php b/other/upgrade.php index 2defe17506..3697bd5d29 100644 --- a/other/upgrade.php +++ b/other/upgrade.php @@ -733,7 +733,7 @@ function loadEssentialData() require_once(Config::$sourcedir . '/Autoloader.php'); - if (class_exists('SMF\\Db\\APIs\\' . Config::$db_type)) + if (class_exists('SMF\\Db\\APIs\\' . Db::type(Config::$db_type))) { // Make the connection... if (empty(Db::$db_connection)) @@ -782,7 +782,7 @@ function loadEssentialData() Db::$db->free_result($request); } else - return throw_error(sprintf(Lang::$txt['error_sourcefile_missing'], 'Db/APIs/' . Config::$db_type . '.php')); + return die(sprintf(Lang::$txt['error_sourcefile_missing'], 'Db/APIs/' . Db::type(Config::$db_type) . '.php')); // If they don't have the file, they're going to get a warning anyway so we won't need to clean request vars. if (class_exists('SMF\\QueryString', false) && php_version_check()) From f18710ae4df04081e8cd7fd5d40713a584ae6e4e Mon Sep 17 00:00:00 2001 From: jdarwood007 Date: Sun, 5 Nov 2023 08:22:44 -0800 Subject: [PATCH 02/11] Rename files so its simple --- other/upgrade.php | 14 +++++++------- ...upgrade_2-0_mysql.sql => upgrade_2-0_MySQL.sql} | 0 ...0_postgresql.sql => upgrade_2-0_PostgreSQL.sql} | 0 ...upgrade_2-1_mysql.sql => upgrade_2-1_MySQL.sql} | 0 ...1_postgresql.sql => upgrade_2-1_PostgreSQL.sql} | 0 5 files changed, 7 insertions(+), 7 deletions(-) rename other/{upgrade_2-0_mysql.sql => upgrade_2-0_MySQL.sql} (100%) rename other/{upgrade_2-0_postgresql.sql => upgrade_2-0_PostgreSQL.sql} (100%) rename other/{upgrade_2-1_mysql.sql => upgrade_2-1_MySQL.sql} (100%) rename other/{upgrade_2-1_postgresql.sql => upgrade_2-1_PostgreSQL.sql} (100%) diff --git a/other/upgrade.php b/other/upgrade.php index 3697bd5d29..5f6d18fb6e 100644 --- a/other/upgrade.php +++ b/other/upgrade.php @@ -815,8 +815,8 @@ function initialize_inputs() // And the extra little files ;). deleteFile(dirname(__FILE__) . '/upgrade_1-0.sql'); deleteFile(dirname(__FILE__) . '/upgrade_1-1.sql'); - deleteFile(dirname(__FILE__) . '/upgrade_2-0_' . Config::$db_type . '.sql'); - deleteFile(dirname(__FILE__) . '/upgrade_2-1_' . Config::$db_type . '.sql'); + deleteFile(dirname(__FILE__) . '/upgrade_2-0_' . Db::type(Config::$db_type) . '.sql'); + deleteFile(dirname(__FILE__) . '/upgrade_2-1_' . Db::type(Config::$db_type) . '.sql'); deleteFile(dirname(__FILE__) . '/upgrade-helper.php'); $dh = opendir(dirname(__FILE__)); @@ -873,12 +873,12 @@ function WelcomeLogin() // Check for some key files - one template, one language, and a new and an old source file. $check = @file_exists(Config::$modSettings['theme_dir'] . '/index.template.php') && @file_exists(Config::$sourcedir . '/QueryString.php') - && @file_exists(Config::$sourcedir . '/Db/APIs/' . Config::$db_type . '.php') - && @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . Config::$db_type . '.sql'); + && @file_exists(Config::$sourcedir . '/Db/APIs/' . Db::type(Config::$db_type) . '.php') + && @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . Db::type(Config::$db_type) . '.sql'); // Need legacy scripts? if (!isset(Config::$modSettings['smfVersion']) || Config::$modSettings['smfVersion'] < 2.1) - $check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . Config::$db_type . '.sql'); + $check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . Db::type(Config::$db_type) . '.sql'); if (!isset(Config::$modSettings['smfVersion']) || Config::$modSettings['smfVersion'] < 2.0) $check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql'); if (!isset(Config::$modSettings['smfVersion']) || Config::$modSettings['smfVersion'] < 1.1) @@ -1677,8 +1677,8 @@ function DatabaseChanges() $files = array( array('upgrade_1-0.sql', '1.1', '1.1 RC0', false), array('upgrade_1-1.sql', '2.0', '2.0 a', false), - array('upgrade_2-0_' . Config::$db_type . '.sql', '2.1', '2.1 dev0', false), - array('upgrade_2-1_' . Config::$db_type . '.sql', '3.0', SMF_VERSION, true), + array('upgrade_2-0_' . Db::type(Config::$db_type) . '.sql', '2.1', '2.1 dev0', false), + array('upgrade_2-1_' . Db::type(Config::$db_type) . '.sql', '3.0', SMF_VERSION, true), ); // How many files are there in total? diff --git a/other/upgrade_2-0_mysql.sql b/other/upgrade_2-0_MySQL.sql similarity index 100% rename from other/upgrade_2-0_mysql.sql rename to other/upgrade_2-0_MySQL.sql diff --git a/other/upgrade_2-0_postgresql.sql b/other/upgrade_2-0_PostgreSQL.sql similarity index 100% rename from other/upgrade_2-0_postgresql.sql rename to other/upgrade_2-0_PostgreSQL.sql diff --git a/other/upgrade_2-1_mysql.sql b/other/upgrade_2-1_MySQL.sql similarity index 100% rename from other/upgrade_2-1_mysql.sql rename to other/upgrade_2-1_MySQL.sql diff --git a/other/upgrade_2-1_postgresql.sql b/other/upgrade_2-1_PostgreSQL.sql similarity index 100% rename from other/upgrade_2-1_postgresql.sql rename to other/upgrade_2-1_PostgreSQL.sql From ddd3c7b73762feea2e859c3a279029b09b96dcb7 Mon Sep 17 00:00:00 2001 From: jdarwood007 Date: Sun, 5 Nov 2023 08:41:59 -0800 Subject: [PATCH 03/11] PHP is complaining about a float to int loss of precision. --- other/upgrade.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/other/upgrade.php b/other/upgrade.php index 5f6d18fb6e..6cdb69ca77 100644 --- a/other/upgrade.php +++ b/other/upgrade.php @@ -4098,13 +4098,13 @@ function template_welcome_message() { $ago = time() - $upcontext['started']; $ago_hours = floor($ago / 3600); - $ago_minutes = intval(($ago / 60) % 60); + $ago_minutes = (int) (((int) ($ago / 60)) % 60); $ago_seconds = intval($ago % 60); $agoTxt = $ago < 60 ? 'upgrade_time_s' : ($ago < 3600 ? 'upgrade_time_ms' : 'upgrade_time_hms'); $updated = time() - $upcontext['updated']; $updated_hours = floor($updated / 3600); - $updated_minutes = intval(($updated / 60) % 60); + $updated_minutes = intval(((int) ($updated / 60)) % 60); $updated_seconds = intval($updated % 60); $updatedTxt = $updated < 60 ? 'upgrade_time_updated_s' : ($updated < 3600 ? 'upgrade_time_updated_hm' : 'upgrade_time_updated_hms'); From 9911b266e1e8735ab3e154e0e0532cef567c73f5 Mon Sep 17 00:00:00 2001 From: jdarwood007 Date: Sun, 5 Nov 2023 08:59:59 -0800 Subject: [PATCH 04/11] Fix issues preventing upgrader from working --- other/upgrade.php | 2 +- other/upgrade_2-1_MySQL.sql | 2 +- other/upgrade_2-1_PostgreSQL.sql | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/other/upgrade.php b/other/upgrade.php index 6cdb69ca77..8e502093f3 100644 --- a/other/upgrade.php +++ b/other/upgrade.php @@ -785,7 +785,7 @@ function loadEssentialData() return die(sprintf(Lang::$txt['error_sourcefile_missing'], 'Db/APIs/' . Db::type(Config::$db_type) . '.php')); // If they don't have the file, they're going to get a warning anyway so we won't need to clean request vars. - if (class_exists('SMF\\QueryString', false) && php_version_check()) + if (class_exists('SMF\\QueryString') && php_version_check()) { QueryString::cleanRequest(); } diff --git a/other/upgrade_2-1_MySQL.sql b/other/upgrade_2-1_MySQL.sql index 1d35c1c0b6..c7675628e5 100644 --- a/other/upgrade_2-1_MySQL.sql +++ b/other/upgrade_2-1_MySQL.sql @@ -321,7 +321,7 @@ INSERT INTO {$db_prefix}settings (variable, value) VALUES ('defaultMaxListItems' Db::$db->insert('replace', '{db_prefix}settings', array('variable' => 'string', 'value' => 'string'), - array('bcrypt_hash_cost', Security::hashVerifyPassword()), + array('bcrypt_hash_cost', Security::hashBenchmark()), array('variable') ); ---} diff --git a/other/upgrade_2-1_PostgreSQL.sql b/other/upgrade_2-1_PostgreSQL.sql index 3285e2fa2e..e40d913292 100644 --- a/other/upgrade_2-1_PostgreSQL.sql +++ b/other/upgrade_2-1_PostgreSQL.sql @@ -2089,7 +2089,7 @@ WHERE variable IN ('show_board_desc', 'display_quick_reply', 'show_mark_read', ' Db::$db->insert('replace', '{db_prefix}settings', array('variable' => 'string', 'value' => 'string'), - array('bcrypt_hash_cost', Security::hashVerifyPassword()), + array('bcrypt_hash_cost', Security::hashBenchmark()), array('variable') ); ---} From 4320cccc344ae63d4982206dfbd4580706a28f28 Mon Sep 17 00:00:00 2001 From: jdarwood007 Date: Sun, 5 Nov 2023 09:01:23 -0800 Subject: [PATCH 05/11] Use getClass instead --- Sources/Db/DatabaseApi.php | 4 ++-- other/upgrade.php | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Sources/Db/DatabaseApi.php b/Sources/Db/DatabaseApi.php index 224608622c..752f69f63a 100644 --- a/Sources/Db/DatabaseApi.php +++ b/Sources/Db/DatabaseApi.php @@ -326,7 +326,7 @@ final public static function load(array $options = []) } // Figure out what type of database we are using. - $class = self::type(!empty(Config::$db_type) ? strtolower(Config::$db_type) : 'mysql'); + $class = self::getClass(!empty(Config::$db_type) ? strtolower(Config::$db_type) : 'mysql'); if (!class_exists(__NAMESPACE__ . '\\APIs\\' . $class)) { ErrorHandler::displayDbError(); @@ -344,7 +344,7 @@ final public static function load(array $options = []) return self::$db; } - public static function type($db_type) + public static function getClass($db_type) { switch (strtolower($db_type)) { // PostgreSQL is known by many names. diff --git a/other/upgrade.php b/other/upgrade.php index 8e502093f3..30a0b8e58e 100644 --- a/other/upgrade.php +++ b/other/upgrade.php @@ -733,7 +733,7 @@ function loadEssentialData() require_once(Config::$sourcedir . '/Autoloader.php'); - if (class_exists('SMF\\Db\\APIs\\' . Db::type(Config::$db_type))) + if (class_exists('SMF\\Db\\APIs\\' . Db::getClass(Config::$db_type))) { // Make the connection... if (empty(Db::$db_connection)) @@ -782,7 +782,7 @@ function loadEssentialData() Db::$db->free_result($request); } else - return die(sprintf(Lang::$txt['error_sourcefile_missing'], 'Db/APIs/' . Db::type(Config::$db_type) . '.php')); + return die(sprintf(Lang::$txt['error_sourcefile_missing'], 'Db/APIs/' . Db::getClass(Config::$db_type) . '.php')); // If they don't have the file, they're going to get a warning anyway so we won't need to clean request vars. if (class_exists('SMF\\QueryString') && php_version_check()) @@ -815,8 +815,8 @@ function initialize_inputs() // And the extra little files ;). deleteFile(dirname(__FILE__) . '/upgrade_1-0.sql'); deleteFile(dirname(__FILE__) . '/upgrade_1-1.sql'); - deleteFile(dirname(__FILE__) . '/upgrade_2-0_' . Db::type(Config::$db_type) . '.sql'); - deleteFile(dirname(__FILE__) . '/upgrade_2-1_' . Db::type(Config::$db_type) . '.sql'); + deleteFile(dirname(__FILE__) . '/upgrade_2-0_' . Db::getClass(Config::$db_type) . '.sql'); + deleteFile(dirname(__FILE__) . '/upgrade_2-1_' . Db::getClass(Config::$db_type) . '.sql'); deleteFile(dirname(__FILE__) . '/upgrade-helper.php'); $dh = opendir(dirname(__FILE__)); @@ -873,12 +873,12 @@ function WelcomeLogin() // Check for some key files - one template, one language, and a new and an old source file. $check = @file_exists(Config::$modSettings['theme_dir'] . '/index.template.php') && @file_exists(Config::$sourcedir . '/QueryString.php') - && @file_exists(Config::$sourcedir . '/Db/APIs/' . Db::type(Config::$db_type) . '.php') - && @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . Db::type(Config::$db_type) . '.sql'); + && @file_exists(Config::$sourcedir . '/Db/APIs/' . Db::getClass(Config::$db_type) . '.php') + && @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . Db::getClass(Config::$db_type) . '.sql'); // Need legacy scripts? if (!isset(Config::$modSettings['smfVersion']) || Config::$modSettings['smfVersion'] < 2.1) - $check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . Db::type(Config::$db_type) . '.sql'); + $check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . Db::getClass(Config::$db_type) . '.sql'); if (!isset(Config::$modSettings['smfVersion']) || Config::$modSettings['smfVersion'] < 2.0) $check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql'); if (!isset(Config::$modSettings['smfVersion']) || Config::$modSettings['smfVersion'] < 1.1) @@ -1677,8 +1677,8 @@ function DatabaseChanges() $files = array( array('upgrade_1-0.sql', '1.1', '1.1 RC0', false), array('upgrade_1-1.sql', '2.0', '2.0 a', false), - array('upgrade_2-0_' . Db::type(Config::$db_type) . '.sql', '2.1', '2.1 dev0', false), - array('upgrade_2-1_' . Db::type(Config::$db_type) . '.sql', '3.0', SMF_VERSION, true), + array('upgrade_2-0_' . Db::getClass(Config::$db_type) . '.sql', '2.1', '2.1 dev0', false), + array('upgrade_2-1_' . Db::getClass(Config::$db_type) . '.sql', '3.0', SMF_VERSION, true), ); // How many files are there in total? From cbe1db578f60ff027c360300568076f7b21c2c46 Mon Sep 17 00:00:00 2001 From: jdarwood007 Date: Sun, 5 Nov 2023 16:03:22 -0800 Subject: [PATCH 06/11] Installer fixes --- Sources/Autoloader.php | 2 +- other/install.php | 14 +++++++------- ...install_2-1_mysql.sql => install_2-1_MySQL.sql} | 0 ...1_postgresql.sql => install_2-1_PostgreSQL.sql} | 0 4 files changed, 8 insertions(+), 8 deletions(-) rename other/{install_2-1_mysql.sql => install_2-1_MySQL.sql} (100%) rename other/{install_2-1_postgresql.sql => install_2-1_PostgreSQL.sql} (100%) diff --git a/Sources/Autoloader.php b/Sources/Autoloader.php index 0a9ffacf16..af7e14e5a5 100644 --- a/Sources/Autoloader.php +++ b/Sources/Autoloader.php @@ -41,7 +41,7 @@ } // Do any third-party scripts want in on the fun? - if (class_exists('SMF\\Config', false) && $hook_value !== (Config::$modSettings['integrate_autoload'] ?? '')) { + if (class_exists('SMF\\Config', false) && !defined('SMF_INSTALLING') && $hook_value !== (Config::$modSettings['integrate_autoload'] ?? '')) { if (!class_exists('SMF\\IntegrationHook', false) && is_file($sourcedir . '/IntegrationHook.php')) { require_once $sourcedir . '/IntegrationHook.php'; } diff --git a/other/install.php b/other/install.php index b603e15cfb..9204efc3f8 100644 --- a/other/install.php +++ b/other/install.php @@ -254,7 +254,7 @@ function initialize_inputs() foreach ($databases as $key => $dummy) { $type = ($key == 'mysqli') ? 'mysql' : $key; - $ftp->unlink('install_' . DB_SCRIPT_VERSION . '_' . $type . '.sql'); + $ftp->unlink('install_' . DB_SCRIPT_VERSION . '_' . Db::getClass($type) . '.sql'); } $ftp->close(); @@ -268,7 +268,7 @@ function initialize_inputs() foreach ($databases as $key => $dummy) { $type = ($key == 'mysqli') ? 'mysql' : $key; - @unlink(Config::$boarddir . '/install_' . DB_SCRIPT_VERSION . '_' . $type . '.sql'); + @unlink(Config::$boarddir . '/install_' . DB_SCRIPT_VERSION . '_' . Db::getClass($type) . '.sql'); } } @@ -479,11 +479,11 @@ function Welcome() if ($db['supported']) { $type = ($key == 'mysqli') ? 'mysql' : $key; - if (!file_exists(Config::$boarddir . '/install_' . DB_SCRIPT_VERSION . '_' . $type . '.sql')) + if (!file_exists(Config::$boarddir . '/install_' . DB_SCRIPT_VERSION . '_' . Db::getClass($type) . '.sql')) { $databases[$key]['supported'] = false; $notFoundSQLFile = true; - Lang::$txt['error_db_script_missing'] = sprintf(Lang::$txt['error_db_script_missing'], 'install_' . DB_SCRIPT_VERSION . '_' . $type . '.sql'); + Lang::$txt['error_db_script_missing'] = sprintf(Lang::$txt['error_db_script_missing'], 'install_' . DB_SCRIPT_VERSION . '_' . Db::getClass($type) . '.sql'); } else $incontext['supported_databases'][] = $db; @@ -868,9 +868,9 @@ function DatabaseSettings() Config::load(); // Better find the database file! - if (!file_exists(Config::$sourcedir . '/Db/APIs/' . Config::$db_type . '.php')) + if (!file_exists(Config::$sourcedir . '/Db/APIs/' . Db::getClase(Config::$db_type) . '.php')) { - $incontext['error'] = sprintf(Lang::$txt['error_db_file'], 'Db/APIs/' . Config::$db_type . '.php'); + $incontext['error'] = sprintf(Lang::$txt['error_db_file'], 'Db/APIs/' . Db::getClase(Config::$db_type) . '.php'); return false; } @@ -1222,7 +1222,7 @@ function DatabasePopulation() // Read in the SQL. Turn this on and that off... internationalize... etc. $type = (Config::$db_type == 'mysqli' ? 'mysql' : Config::$db_type); - $sql_lines = explode("\n", strtr(implode(' ', file(Config::$boarddir . '/install_' . DB_SCRIPT_VERSION . '_' . $type . '.sql')), $replaces)); + $sql_lines = explode("\n", strtr(implode(' ', file(Config::$boarddir . '/install_' . DB_SCRIPT_VERSION . '_' . Db::getClass($type) . '.sql')), $replaces)); // Execute the SQL. $current_statement = ''; diff --git a/other/install_2-1_mysql.sql b/other/install_2-1_MySQL.sql similarity index 100% rename from other/install_2-1_mysql.sql rename to other/install_2-1_MySQL.sql diff --git a/other/install_2-1_postgresql.sql b/other/install_2-1_PostgreSQL.sql similarity index 100% rename from other/install_2-1_postgresql.sql rename to other/install_2-1_PostgreSQL.sql From 4a97b333bcae3323173ea2a6137662621da36452 Mon Sep 17 00:00:00 2001 From: jdarwood007 Date: Sun, 5 Nov 2023 19:48:34 -0800 Subject: [PATCH 07/11] typos --- Sources/Autoloader.php | 2 +- other/install.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/Autoloader.php b/Sources/Autoloader.php index af7e14e5a5..7587143848 100644 --- a/Sources/Autoloader.php +++ b/Sources/Autoloader.php @@ -41,7 +41,7 @@ } // Do any third-party scripts want in on the fun? - if (class_exists('SMF\\Config', false) && !defined('SMF_INSTALLING') && $hook_value !== (Config::$modSettings['integrate_autoload'] ?? '')) { + if (!defined('SMF_INSTALLING') && class_exists('SMF\\Config', false) && $hook_value !== (Config::$modSettings['integrate_autoload'] ?? '')) { if (!class_exists('SMF\\IntegrationHook', false) && is_file($sourcedir . '/IntegrationHook.php')) { require_once $sourcedir . '/IntegrationHook.php'; } diff --git a/other/install.php b/other/install.php index 9204efc3f8..e43c7b262c 100644 --- a/other/install.php +++ b/other/install.php @@ -868,9 +868,9 @@ function DatabaseSettings() Config::load(); // Better find the database file! - if (!file_exists(Config::$sourcedir . '/Db/APIs/' . Db::getClase(Config::$db_type) . '.php')) + if (!file_exists(Config::$sourcedir . '/Db/APIs/' . Db::getClass(Config::$db_type) . '.php')) { - $incontext['error'] = sprintf(Lang::$txt['error_db_file'], 'Db/APIs/' . Db::getClase(Config::$db_type) . '.php'); + $incontext['error'] = sprintf(Lang::$txt['error_db_file'], 'Db/APIs/' . Db::getClass(Config::$db_type) . '.php'); return false; } From 29371cad93b31515394504336ee81dbd17f95aba Mon Sep 17 00:00:00 2001 From: jdarwood007 Date: Sun, 5 Nov 2023 20:01:31 -0800 Subject: [PATCH 08/11] Fix up errors during connection on installer --- Sources/Db/APIs/MySQL.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Sources/Db/APIs/MySQL.php b/Sources/Db/APIs/MySQL.php index faa524c072..d5f3c58884 100644 --- a/Sources/Db/APIs/MySQL.php +++ b/Sources/Db/APIs/MySQL.php @@ -1984,8 +1984,11 @@ protected function __construct(array $options = []) $this->prefixReservedTables(); } - $this->get_version(); - $this->supports_pcre = version_compare($this->version, strpos($this->version, 'MariaDB') !== false ? '10.0.5' : '8.0.4', '>='); + if (empty($this->connection) && !$non_fatal) + { + $this->get_version(); + $this->supports_pcre = version_compare($this->version, strpos($this->version, 'MariaDB') !== false ? '10.0.5' : '8.0.4', '>='); + } // For backward compatibility. if (!is_object(self::$db_connection)) { From c6e2a4f8516d23bada5754b583fcd1ec38457eca Mon Sep 17 00:00:00 2001 From: jdarwood007 Date: Tue, 21 Nov 2023 18:57:32 -0800 Subject: [PATCH 09/11] PSR12 --- Sources/Db/APIs/MySQL.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Sources/Db/APIs/MySQL.php b/Sources/Db/APIs/MySQL.php index d5f3c58884..36d2c38d9f 100644 --- a/Sources/Db/APIs/MySQL.php +++ b/Sources/Db/APIs/MySQL.php @@ -1984,8 +1984,7 @@ protected function __construct(array $options = []) $this->prefixReservedTables(); } - if (empty($this->connection) && !$non_fatal) - { + if (empty($this->connection) && !$non_fatal) { $this->get_version(); $this->supports_pcre = version_compare($this->version, strpos($this->version, 'MariaDB') !== false ? '10.0.5' : '8.0.4', '>='); } From 4bd7b43c8663d11a509641ff0ee1c8ea77a30208 Mon Sep 17 00:00:00 2001 From: jdarwood007 Date: Sat, 25 Nov 2023 09:03:57 -0800 Subject: [PATCH 10/11] Adjust the logic to exit the construct early if we don't have a connection --- Sources/Db/APIs/MySQL.php | 16 ++++++++++------ Sources/Db/APIs/PostgreSQL.php | 5 +++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Sources/Db/APIs/MySQL.php b/Sources/Db/APIs/MySQL.php index 36d2c38d9f..60b56f089d 100644 --- a/Sources/Db/APIs/MySQL.php +++ b/Sources/Db/APIs/MySQL.php @@ -1984,20 +1984,24 @@ protected function __construct(array $options = []) $this->prefixReservedTables(); } - if (empty($this->connection) && !$non_fatal) { - $this->get_version(); - $this->supports_pcre = version_compare($this->version, strpos($this->version, 'MariaDB') !== false ? '10.0.5' : '8.0.4', '>='); - } - // For backward compatibility. if (!is_object(self::$db_connection)) { self::$db_connection = $this->connection; } + // At this point, if we don't have a connection, nothing else can be done. + if (empty($this->connection)) { + return; + } + + $this->get_version(); + $this->supports_pcre = version_compare($this->version, strpos($this->version, 'MariaDB') !== false ? '10.0.5' : '8.0.4', '>='); + // Ensure database has UTF-8 as its default input charset. $this->query( '', - 'SET NAMES {string:db_character_set}', + ' + SET NAMES {string:db_character_set}', [ 'db_character_set' => $this->character_set, ], diff --git a/Sources/Db/APIs/PostgreSQL.php b/Sources/Db/APIs/PostgreSQL.php index 3d5493c690..cf76afa618 100644 --- a/Sources/Db/APIs/PostgreSQL.php +++ b/Sources/Db/APIs/PostgreSQL.php @@ -2117,6 +2117,11 @@ protected function __construct(array $options = []) self::$db_connection = $this->connection; } + // At this point, if we don't have a connection, nothing else can be done. + if (empty($this->connection)) { + return; + } + // Ensure database has UTF-8 as its default input charset. $this->query( '', From 2face9467da068fb90dad878e41d6db7f24a7b7a Mon Sep 17 00:00:00 2001 From: jdarwood007 Date: Sun, 26 Nov 2023 15:40:53 -0800 Subject: [PATCH 11/11] Move the check --- Sources/Db/APIs/MySQL.php | 13 ++++++------- Sources/Db/APIs/PostgreSQL.php | 10 +++++----- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/Sources/Db/APIs/MySQL.php b/Sources/Db/APIs/MySQL.php index 60b56f089d..d3f7d473a0 100644 --- a/Sources/Db/APIs/MySQL.php +++ b/Sources/Db/APIs/MySQL.php @@ -1984,24 +1984,23 @@ protected function __construct(array $options = []) $this->prefixReservedTables(); } - // For backward compatibility. - if (!is_object(self::$db_connection)) { - self::$db_connection = $this->connection; - } - // At this point, if we don't have a connection, nothing else can be done. if (empty($this->connection)) { return; } + // For backward compatibility. + if (!is_object(self::$db_connection)) { + self::$db_connection = $this->connection; + } + $this->get_version(); $this->supports_pcre = version_compare($this->version, strpos($this->version, 'MariaDB') !== false ? '10.0.5' : '8.0.4', '>='); // Ensure database has UTF-8 as its default input charset. $this->query( '', - ' - SET NAMES {string:db_character_set}', + 'SET NAMES {string:db_character_set}', [ 'db_character_set' => $this->character_set, ], diff --git a/Sources/Db/APIs/PostgreSQL.php b/Sources/Db/APIs/PostgreSQL.php index cf76afa618..c668f5d4fa 100644 --- a/Sources/Db/APIs/PostgreSQL.php +++ b/Sources/Db/APIs/PostgreSQL.php @@ -2112,16 +2112,16 @@ protected function __construct(array $options = []) ErrorHandler::displayDbError(); } - // For backward compatibility. - if (!is_object(self::$db_connection)) { - self::$db_connection = $this->connection; - } - // At this point, if we don't have a connection, nothing else can be done. if (empty($this->connection)) { return; } + // For backward compatibility. + if (!is_object(self::$db_connection)) { + self::$db_connection = $this->connection; + } + // Ensure database has UTF-8 as its default input charset. $this->query( '',