From 1369efedd573a95ac286a007f6ed4a1b924b089d Mon Sep 17 00:00:00 2001 From: sbulen Date: Wed, 21 Jul 2021 22:54:31 -0700 Subject: [PATCH 1/2] UTF8 settings usage changes Signed by Shawn Bulen, bulens@pacbell.net --- other/install.php | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/other/install.php b/other/install.php index 8f53d54de9..10b240c60d 100644 --- a/other/install.php +++ b/other/install.php @@ -1060,24 +1060,21 @@ function ForumSettings() require(dirname(__FILE__) . '/Settings.php'); // UTF-8 requires a setting to override the language charset. - if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8']))) + if (!$databases[$db_type]['utf8_support']()) { - if (!$databases[$db_type]['utf8_support']()) - { - $incontext['error'] = sprintf($txt['error_utf8_support']); - return false; - } + $incontext['error'] = sprintf($txt['error_utf8_support']); + return false; + } - if (!empty($databases[$db_type]['utf8_version_check']) && version_compare($databases[$db_type]['utf8_version'], preg_replace('~\-.+?$~', '', eval($databases[$db_type]['utf8_version_check'])), '>')) - { - $incontext['error'] = sprintf($txt['error_utf8_version'], $databases[$db_type]['utf8_version']); - return false; - } - else - // Set the character set here. - installer_updateSettingsFile(array('db_character_set' => 'utf8')); + if (!empty($databases[$db_type]['utf8_version_check']) && version_compare($databases[$db_type]['utf8_version'], preg_replace('~\-.+?$~', '', eval($databases[$db_type]['utf8_version_check'])), '>')) + { + $incontext['error'] = sprintf($txt['error_utf8_version'], $databases[$db_type]['utf8_version']); + return false; } + // Set the character set here. + installer_updateSettingsFile(array('db_character_set' => 'utf8')); + // Good, skip on. return true; } @@ -1186,12 +1183,9 @@ function DatabasePopulation() $replaces['{$engine}'] = $has_innodb ? 'InnoDB' : 'MyISAM'; $replaces['{$memory}'] = (!$has_innodb && in_array('MEMORY', $engines)) ? 'MEMORY' : $replaces['{$engine}']; - // If the UTF-8 setting was enabled, add it to the table definitions. - if (!empty($databases[$db_type]['utf8_support']) && (!empty($databases[$db_type]['utf8_required']) || isset($_POST['utf8']))) - { - $replaces['{$engine}'] .= ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci'; - $replaces['{$memory}'] .= ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci'; - } + // UTF-8 is required. + $replaces['{$engine}'] .= ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci'; + $replaces['{$memory}'] .= ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci'; // One last thing - if we don't have InnoDB, we can't do transactions... if (!$has_innodb) @@ -1288,8 +1282,7 @@ function DatabasePopulation() } // Make sure UTF will be used globally. - if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8']))) - $newSettings[] = array('global_character_set', 'UTF-8'); + $newSettings[] = array('global_character_set', 'UTF-8'); // Are we allowing stat collection? if (!empty($_POST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats']) && empty($modSettings['enable_sm_stats'])) From e81e51613adf5ef304a7731e0e9730f8518650df Mon Sep 17 00:00:00 2001 From: sbulen Date: Thu, 22 Jul 2021 14:35:50 -0700 Subject: [PATCH 2/2] New tables should always be utf8 Signed by Shawn Bulen, bulens@pacbell.net --- other/upgrade.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/other/upgrade.php b/other/upgrade.php index e4edbec78e..565a96f7fd 100644 --- a/other/upgrade.php +++ b/other/upgrade.php @@ -2021,8 +2021,7 @@ function($errno, $errstr, $errfile, $errline) use ($support_js) $last_step = ''; // Make sure all newly created tables will have the proper characters set; this approach is used throughout upgrade_2-1_mysql.php - if (isset($db_character_set) && $db_character_set === 'utf8') - $lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines); + $lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines); // Count the total number of steps within this file - for progress. $file_steps = substr_count(implode('', $lines), '---#');