From a0e6067a42eb8cf77d27a76ebe63d724975bd2bc Mon Sep 17 00:00:00 2001 From: Jon Stovell Date: Thu, 2 May 2024 16:06:41 -0600 Subject: [PATCH 1/6] Fixes syntax errors in upgrade_3-0_*.sql files Signed-off-by: Jon Stovell --- other/upgrade_3-0_MySQL.sql | 16 ++++++++-------- other/upgrade_3-0_PostgreSQL.sql | 14 +++++++------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/other/upgrade_3-0_MySQL.sql b/other/upgrade_3-0_MySQL.sql index 6718878662..5845597027 100644 --- a/other/upgrade_3-0_MySQL.sql +++ b/other/upgrade_3-0_MySQL.sql @@ -110,15 +110,15 @@ ADD COLUMN version VARCHAR(5) NOT NULL DEFAULT ''; ---# Add duration, rrule, rdates, and exdates columns to calendar table ALTER TABLE {$db_prefix}calendar -MODIFY COLUMN start_date DATE AFTER id_member; -ADD COLUMN duration VARCHAR(32) NOT NULL DEFAULT ''; -ADD COLUMN rrule VARCHAR(1024) NOT NULL DEFAULT 'FREQ=YEARLY;COUNT=1'; -ADD COLUMN rdates TEXT NOT NULL; -ADD COLUMN exdates TEXT NOT NULL; -ADD COLUMN adjustments JSON DEFAULT NULL; -ADD COLUMN sequence SMALLINT UNSIGNED NOT NULL DEFAULT '0'; +MODIFY COLUMN start_date DATE AFTER id_member, +ADD COLUMN duration VARCHAR(32) NOT NULL DEFAULT '', +ADD COLUMN rrule VARCHAR(1024) NOT NULL DEFAULT 'FREQ=YEARLY;COUNT=1', +ADD COLUMN rdates TEXT NOT NULL, +ADD COLUMN exdates TEXT NOT NULL, +ADD COLUMN adjustments JSON DEFAULT NULL, +ADD COLUMN sequence SMALLINT UNSIGNED NOT NULL DEFAULT '0', ADD COLUMN uid VARCHAR(255) NOT NULL DEFAULT '', -ADD COLUMN type TINYINT UNSIGNED NOT NULL DEFAULT '0'; +ADD COLUMN type TINYINT UNSIGNED NOT NULL DEFAULT '0', ADD COLUMN enabled TINYINT UNSIGNED NOT NULL DEFAULT '1'; ---# diff --git a/other/upgrade_3-0_PostgreSQL.sql b/other/upgrade_3-0_PostgreSQL.sql index 1f250d6221..25db6d7c7d 100644 --- a/other/upgrade_3-0_PostgreSQL.sql +++ b/other/upgrade_3-0_PostgreSQL.sql @@ -110,14 +110,14 @@ ADD COLUMN IF NOT EXISTS version VARCHAR(5) NOT NULL DEFAULT ''; ---# Add duration, rrule, rdates, and exdates columns to calendar table ALTER TABLE {$db_prefix}calendar -ADD COLUMN IF NOT EXISTS duration varchar(32) NOT NULL DEFAULT ''; -ADD COLUMN IF NOT EXISTS rrule varchar(1024) NOT NULL DEFAULT 'FREQ=YEARLY;COUNT=1'; -ADD COLUMN IF NOT EXISTS rdates text NOT NULL; -ADD COLUMN IF NOT EXISTS exdates text NOT NULL; -ADD COLUMN IF NOT EXISTS adjustments jsonb DEFAULT NULL; -ADD COLUMN IF NOT EXISTS sequence smallint NOT NULL DEFAULT '0'; +ADD COLUMN IF NOT EXISTS duration varchar(32) NOT NULL DEFAULT '', +ADD COLUMN IF NOT EXISTS rrule varchar(1024) NOT NULL DEFAULT 'FREQ=YEARLY;COUNT=1', +ADD COLUMN IF NOT EXISTS rdates text NOT NULL, +ADD COLUMN IF NOT EXISTS exdates text NOT NULL, +ADD COLUMN IF NOT EXISTS adjustments jsonb DEFAULT NULL, +ADD COLUMN IF NOT EXISTS sequence smallint NOT NULL DEFAULT '0', ADD COLUMN IF NOT EXISTS uid varchar(255) NOT NULL DEFAULT '', -ADD COLUMN IF NOT EXISTS type smallint NOT NULL DEFAULT '0'; +ADD COLUMN IF NOT EXISTS type smallint NOT NULL DEFAULT '0', ADD COLUMN IF NOT EXISTS enabled smallint NOT NULL DEFAULT '1'; ---# From c08eb77f9fc1c8d26d95f1dbc615902faef7a831 Mon Sep 17 00:00:00 2001 From: Jon Stovell Date: Thu, 2 May 2024 16:04:12 -0600 Subject: [PATCH 2/6] Supports `{$db_name}` substitution in upgrader Signed-off-by: Jon Stovell --- other/upgrade.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/other/upgrade.php b/other/upgrade.php index 41f4ea33d1..893b07dba2 100644 --- a/other/upgrade.php +++ b/other/upgrade.php @@ -2291,6 +2291,7 @@ function parse_sql($filename) - {$boarddir} - {$boardurl} - {$db_prefix} + - {$db_name} - {$db_collation} */ @@ -2484,7 +2485,7 @@ function ($errno, $errstr, $errfile, $errline) use ($support_js) { } // {$sboarddir} is deprecated, but blah blah backward compatibility blah... - $current_data = strtr(substr(rtrim($current_data), 0, -1), ['{$db_prefix}' => Config::$db_prefix, '{$boarddir}' => Db::$db->escape_string(Config::$boarddir), '{$sboarddir}' => Db::$db->escape_string(Config::$boarddir), '{$boardurl}' => Config::$boardurl, '{$db_collation}' => $db_collation]); + $current_data = strtr(substr(rtrim($current_data), 0, -1), ['{$db_name}' => Config::$db_name, '{$db_prefix}' => Config::$db_prefix, '{$boarddir}' => Db::$db->escape_string(Config::$boarddir), '{$sboarddir}' => Db::$db->escape_string(Config::$boarddir), '{$boardurl}' => Config::$boardurl, '{$db_collation}' => $db_collation]); upgrade_query($current_data); From 590272fb25e325318a6ad14f58c15ff54eefb91a Mon Sep 17 00:00:00 2001 From: Jon Stovell Date: Thu, 2 May 2024 16:08:24 -0600 Subject: [PATCH 3/6] Adds some conditional checks in upgrade_3-0_8.sql files Signed-off-by: Jon Stovell --- other/upgrade_3-0_MySQL.sql | 74 +++++++++++++++++++++++++------- other/upgrade_3-0_PostgreSQL.sql | 17 ++++++++ 2 files changed, 76 insertions(+), 15 deletions(-) diff --git a/other/upgrade_3-0_MySQL.sql b/other/upgrade_3-0_MySQL.sql index 5845597027..d561c7cf64 100644 --- a/other/upgrade_3-0_MySQL.sql +++ b/other/upgrade_3-0_MySQL.sql @@ -95,13 +95,31 @@ foreach (Config::$modSettings as $variable => $value) { /******************************************************************************/ ---# Adding a new column "version" to messages table -ALTER TABLE {$db_prefix}messages -ADD COLUMN version VARCHAR(5) NOT NULL DEFAULT ''; +IF NOT EXISTS( + SELECT NULL + FROM INFORMATION_SCHEMA.COLUMNS + WHERE table_name = '{$db_prefix}messages' + AND table_schema = '{$db_name}' + AND column_name = 'version' +) +THEN + ALTER TABLE {$db_prefix}messages + ADD COLUMN version VARCHAR(5) NOT NULL DEFAULT ''; +END IF; ---# ---# Adding a new column "version" to personal_messages table -ALTER TABLE {$db_prefix}personal_messages -ADD COLUMN version VARCHAR(5) NOT NULL DEFAULT ''; +IF NOT EXISTS( + SELECT NULL + FROM INFORMATION_SCHEMA.COLUMNS + WHERE table_name = '{$db_prefix}personal_messages' + AND table_schema = '{$db_name}' + AND column_name = 'version' +) +THEN + ALTER TABLE {$db_prefix}personal_messages + ADD COLUMN version VARCHAR(5) NOT NULL DEFAULT ''; +END IF; ---# /******************************************************************************/ @@ -109,21 +127,31 @@ ADD COLUMN version VARCHAR(5) NOT NULL DEFAULT ''; /******************************************************************************/ ---# Add duration, rrule, rdates, and exdates columns to calendar table -ALTER TABLE {$db_prefix}calendar -MODIFY COLUMN start_date DATE AFTER id_member, -ADD COLUMN duration VARCHAR(32) NOT NULL DEFAULT '', -ADD COLUMN rrule VARCHAR(1024) NOT NULL DEFAULT 'FREQ=YEARLY;COUNT=1', -ADD COLUMN rdates TEXT NOT NULL, -ADD COLUMN exdates TEXT NOT NULL, -ADD COLUMN adjustments JSON DEFAULT NULL, -ADD COLUMN sequence SMALLINT UNSIGNED NOT NULL DEFAULT '0', -ADD COLUMN uid VARCHAR(255) NOT NULL DEFAULT '', -ADD COLUMN type TINYINT UNSIGNED NOT NULL DEFAULT '0', -ADD COLUMN enabled TINYINT UNSIGNED NOT NULL DEFAULT '1'; +IF NOT EXISTS( + SELECT NULL + FROM INFORMATION_SCHEMA.COLUMNS + WHERE table_name = '{$db_prefix}calendar' + AND table_schema = '{$db_name}' + AND column_name = 'rrule' +) +THEN + ALTER TABLE {$db_prefix}calendar + MODIFY COLUMN start_date DATE AFTER id_member, + ADD COLUMN duration VARCHAR(32) NOT NULL DEFAULT '', + ADD COLUMN rrule VARCHAR(1024) NOT NULL DEFAULT 'FREQ=YEARLY;COUNT=1', + ADD COLUMN rdates TEXT NOT NULL, + ADD COLUMN exdates TEXT NOT NULL, + ADD COLUMN adjustments JSON DEFAULT NULL, + ADD COLUMN sequence SMALLINT UNSIGNED NOT NULL DEFAULT '0', + ADD COLUMN uid VARCHAR(255) NOT NULL DEFAULT '', + ADD COLUMN type TINYINT UNSIGNED NOT NULL DEFAULT '0', + ADD COLUMN enabled TINYINT UNSIGNED NOT NULL DEFAULT '1'; +END IF; ---# ---# Set duration and rrule values and change end_date ---{ +if (version_compare(str_replace(' ', '.', trim(strtolower(@Config::$modSettings['smfVersion']))), '3.0.foo', '<')) $updates = []; $request = Db::$db->query( @@ -177,6 +205,7 @@ ADD COLUMN enabled TINYINT UNSIGNED NOT NULL DEFAULT '1'; $changes ); } +} ---} ---# @@ -187,6 +216,21 @@ DROP COLUMN end_time; ---# Migrate holidays to events ---{ +$request = Db::$db->query( + '', + 'SELECT 1 + FROM information_schema.tables + WHERE table_schema = {string:db_name} + AND table_name = {string:table_name}', + [ + 'db_name' => Config::$db_name, + 'table_name' => Config::$db_prefix . 'calendar_holidays', + ] +); +$exists = Db::$db->num_rows($request) > 0; +Db::$db->free_result($request); + +if ($exists) { $known_holidays = [ 'April Fools' => [ 'title' => "April Fools' Day", diff --git a/other/upgrade_3-0_PostgreSQL.sql b/other/upgrade_3-0_PostgreSQL.sql index 25db6d7c7d..5183f512f5 100644 --- a/other/upgrade_3-0_PostgreSQL.sql +++ b/other/upgrade_3-0_PostgreSQL.sql @@ -123,6 +123,7 @@ ADD COLUMN IF NOT EXISTS enabled smallint NOT NULL DEFAULT '1'; ---# Set duration and rrule values and change end_date ---{ +if (version_compare(str_replace(' ', '.', trim(strtolower(@Config::$modSettings['smfVersion']))), '3.0.foo', '<')) $updates = []; $request = Db::$db->query( @@ -186,6 +187,21 @@ DROP COLUMN end_time; ---# Migrate holidays to events ---{ +$request = Db::$db->query( + '', + 'SELECT 1 + FROM information_schema.tables + WHERE table_schema = {string:db_name} + AND table_name = {string:table_name}', + [ + 'db_name' => Config::$db_name, + 'table_name' => Config::$db_prefix . 'calendar_holidays', + ] +); +$exists = Db::$db->num_rows($request) > 0; +Db::$db->free_result($request); + +if ($exists) { $known_holidays = [ 'April Fools' => [ 'title' => "April Fools' Day", @@ -802,6 +818,7 @@ DROP COLUMN end_time; } Db::$db->free_result($request); +} ---} ---# From d684bab19c23da0b71592efb671a031c9b7ebad9 Mon Sep 17 00:00:00 2001 From: Jon Stovell Date: Fri, 3 May 2024 18:39:40 -0600 Subject: [PATCH 4/6] Uses database API for conditional logic in upgrade_3-0_MySQL.sql Signed-off-by: Jon Stovell --- other/upgrade_3-0_MySQL.sql | 202 ++++++++++++++++++++++++------------ 1 file changed, 133 insertions(+), 69 deletions(-) diff --git a/other/upgrade_3-0_MySQL.sql b/other/upgrade_3-0_MySQL.sql index d561c7cf64..9b46c6759f 100644 --- a/other/upgrade_3-0_MySQL.sql +++ b/other/upgrade_3-0_MySQL.sql @@ -4,6 +4,7 @@ --- Language Upgrade... /******************************************************************************/ +---# Upgrading language settings ---{ $limit = 10000; $statements = []; @@ -95,63 +96,143 @@ foreach (Config::$modSettings as $variable => $value) { /******************************************************************************/ ---# Adding a new column "version" to messages table -IF NOT EXISTS( - SELECT NULL - FROM INFORMATION_SCHEMA.COLUMNS - WHERE table_name = '{$db_prefix}messages' - AND table_schema = '{$db_name}' - AND column_name = 'version' -) -THEN - ALTER TABLE {$db_prefix}messages - ADD COLUMN version VARCHAR(5) NOT NULL DEFAULT ''; -END IF; +---{ +$cols = Db::$db->list_columns('{db_prefix}messages'); + +if (!in_array('version', $cols)) { + Db::$db->add_column( + '{db_prefix}messages', + [ + 'name' => 'version', + 'type' => 'varchar', + 'size' => 5, + 'null' => false, + 'default' => '', + ], + ); +} +---} ---# ---# Adding a new column "version" to personal_messages table -IF NOT EXISTS( - SELECT NULL - FROM INFORMATION_SCHEMA.COLUMNS - WHERE table_name = '{$db_prefix}personal_messages' - AND table_schema = '{$db_name}' - AND column_name = 'version' -) -THEN - ALTER TABLE {$db_prefix}personal_messages - ADD COLUMN version VARCHAR(5) NOT NULL DEFAULT ''; -END IF; +---{ +$cols = Db::$db->list_columns('{db_prefix}personal_messages'); + +if (!in_array('version', $cols)) { + Db::$db->add_column( + '{db_prefix}personal_messages', + [ + 'name' => 'version', + 'type' => 'varchar', + 'size' => 5, + 'null' => false, + 'default' => '', + ], + ); +} +---} ---# /******************************************************************************/ --- Adding support for recurring events... /******************************************************************************/ ----# Add duration, rrule, rdates, and exdates columns to calendar table -IF NOT EXISTS( - SELECT NULL - FROM INFORMATION_SCHEMA.COLUMNS - WHERE table_name = '{$db_prefix}calendar' - AND table_schema = '{$db_name}' - AND column_name = 'rrule' -) -THEN - ALTER TABLE {$db_prefix}calendar - MODIFY COLUMN start_date DATE AFTER id_member, - ADD COLUMN duration VARCHAR(32) NOT NULL DEFAULT '', - ADD COLUMN rrule VARCHAR(1024) NOT NULL DEFAULT 'FREQ=YEARLY;COUNT=1', - ADD COLUMN rdates TEXT NOT NULL, - ADD COLUMN exdates TEXT NOT NULL, - ADD COLUMN adjustments JSON DEFAULT NULL, - ADD COLUMN sequence SMALLINT UNSIGNED NOT NULL DEFAULT '0', - ADD COLUMN uid VARCHAR(255) NOT NULL DEFAULT '', - ADD COLUMN type TINYINT UNSIGNED NOT NULL DEFAULT '0', - ADD COLUMN enabled TINYINT UNSIGNED NOT NULL DEFAULT '1'; -END IF; ----# - ----# Set duration and rrule values and change end_date +---# Adding support for recurring events... ---{ -if (version_compare(str_replace(' ', '.', trim(strtolower(@Config::$modSettings['smfVersion']))), '3.0.foo', '<')) +$cols = Db::$db->list_columns('{db_prefix}calendar'); + +if (!in_array('rrule', $cols)) { + Db::$db->query( + '', + 'ALTER TABLE {db_prefix}calendar + MODIFY COLUMN start_date DATE AFTER id_member', + [], + ); + Db::$db->add_column( + '{db_prefix}calendar', + [ + 'name' => 'duration', + 'type' => 'varchar', + 'size' => 32, + 'null' => false, + 'default' => '', + ], + ); + Db::$db->add_column( + '{db_prefix}calendar', + [ + 'name' => 'rrule', + 'type' => 'varchar', + 'size' => 1024, + 'null' => false, + 'default' => 'FREQ=YEARLY;COUNT=1', + ], + ); + Db::$db->add_column( + '{db_prefix}calendar', + [ + 'name' => 'rdates', + 'type' => 'text', + 'null' => false, + ], + ); + Db::$db->add_column( + '{db_prefix}calendar', + [ + 'name' => 'exdates', + 'type' => 'text', + 'null' => false, + ], + ); + Db::$db->add_column( + '{db_prefix}calendar', + [ + 'name' => 'adjustments', + 'type' => 'json', + 'null' => true, + ], + ); + Db::$db->add_column( + '{db_prefix}calendar', + [ + 'name' => 'sequence', + 'type' => 'smallint', + 'unsigned' => true, + 'null' => false, + 'default' => 0, + ], + ); + Db::$db->add_column( + '{db_prefix}calendar', + [ + 'name' => 'uid', + 'type' => 'varchar', + 'size' => 255, + 'null' => false, + 'default' => '', + ], + ); + Db::$db->add_column( + '{db_prefix}calendar', + [ + 'name' => 'type', + 'type' => 'tinyint', + 'unsigned' => true, + 'null' => false, + 'default' => 0, + ], + ); + Db::$db->add_column( + '{db_prefix}calendar', + [ + 'name' => 'enabled', + 'type' => 'tinyint', + 'unsigned' => true, + 'null' => false, + 'default' => 1, + ], + ); + $updates = []; $request = Db::$db->query( @@ -205,30 +286,15 @@ if (version_compare(str_replace(' ', '.', trim(strtolower(@Config::$modSettings[ $changes ); } + + Db::$db->remove_column('{db_prefix}calendar', 'end_time'); } ---} ---# ----# Drop end_time column from calendar table -ALTER TABLE {$db_prefix}calendar -DROP COLUMN end_time; ----# - ---# Migrate holidays to events ---{ -$request = Db::$db->query( - '', - 'SELECT 1 - FROM information_schema.tables - WHERE table_schema = {string:db_name} - AND table_name = {string:table_name}', - [ - 'db_name' => Config::$db_name, - 'table_name' => Config::$db_prefix . 'calendar_holidays', - ] -); -$exists = Db::$db->num_rows($request) > 0; -Db::$db->free_result($request); +$exists = count(Db::$db->list_tables(false, '%calendar_holidays')) > 0; if ($exists) { $known_holidays = [ @@ -847,9 +913,7 @@ if ($exists) { } Db::$db->free_result($request); ----} ----# ----# Dropping "calendar_holidays" -DROP TABLE IF EXISTS {$db_prefix}calendar_holidays; + Db::$db->drop_table('{db_prefix}calendar_holidays'); +---} ---# \ No newline at end of file From 95ff873c7dbe32159cc3e4fca977c12886a405c0 Mon Sep 17 00:00:00 2001 From: Jon Stovell Date: Sat, 4 May 2024 14:38:00 -0600 Subject: [PATCH 5/6] Fixes issues with loading the correct language in the upgrader Signed-off-by: Jon Stovell --- other/upgrade.php | 59 +++++++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/other/upgrade.php b/other/upgrade.php index 893b07dba2..658c12f0d8 100644 --- a/other/upgrade.php +++ b/other/upgrade.php @@ -539,15 +539,24 @@ function load_lang_file() static $lang_dir = '', $detected_languages = [], $loaded_langfile = ''; - $lang_dir = Config::$languagesdir; + if (isset(Config::$language)) { + $current_language = Lang::getLocaleFromLanguageName(Config::$language); + } + + if (isset($upcontext['language'])) { + $locale = Lang::getLocaleFromLanguageName($upcontext['language']); + $upcontext['language'] = $locale ?? $upcontext['language']; + } + + $lang_dir = !empty(Config::$languagesdir) ? Config::$languagesdir : fixRelativePath(Config::$boarddir) . '/Languages'; // Override the language file? if (isset($upcontext['language']) && file_exists($lang_dir . '/' . $upcontext['language'] . '/Install.php')) { $_SESSION['upgrader_lang'] = $upcontext['language']; } elseif (isset($upcontext['lang']) && file_exists($lang_dir . '/' . $upcontext['lang'] . '/Install.php')) { $_SESSION['upgrader_lang'] = $upcontext['lang']; - } elseif (isset(Config::$language) && file_exists($lang_dir . '/' . Config::$language . '/Install.php')) { - $_SESSION['upgrader_lang'] = Config::$language; + } elseif (isset($current_language) && file_exists($lang_dir . '/' . $current_language . '/Install.php')) { + $_SESSION['upgrader_lang'] = $current_language; } else { $_SESSION['upgrader_lang'] = 'en_US'; } @@ -570,12 +579,12 @@ function load_lang_file() continue; } - if (!is_dir(Config::$languagesdir . '/' . $entry) || !file_exists(Config::$languagesdir . '/' . $entry . '/' . 'Install.php') || !file_exists(Config::$languagesdir . '/' . $entry . '/' . 'General.php')) { + if (!is_dir($lang_dir . '/' . $entry) || !file_exists($lang_dir . '/' . $entry . '/' . 'Install.php') || !file_exists($lang_dir . '/' . $entry . '/' . 'General.php')) { continue; } // Get the line we need. - $fp = @fopen(Config::$languagesdir . '/' . $entry . '/' . 'General.php', 'r'); + $fp = @fopen($lang_dir . '/' . $entry . '/' . 'General.php', 'r'); // Yay! if ($fp) { @@ -605,7 +614,7 @@ function load_lang_file() } $dir->close(); } - // Our guess was wrong, but that's fine. We'll try again after Config::$Languagesdir is defined. + // Our guess was wrong, but that's fine. We'll try again after Config::$languagesdir is defined. elseif (!isset(Config::$languagesdir)) { // Define a few essential strings for now. Lang::$txt['error_db_connect_settings'] = 'Cannot connect to the database server.

Please check that the database info variables are correct in Settings.php.'; @@ -1037,12 +1046,14 @@ function WelcomeLogin() quickFileWritable($cachedir_temp . '/db_last_error.php'); - if (!file_exists(Config::$languagesdir . '/' . $upcontext['language'] . '/General.php')) { + $lang_dir = !empty(Config::$languagesdir) ? Config::$languagesdir : fixRelativePath(Config::$boarddir) . '/Languages'; + + if (!file_exists($lang_dir . '/' . $upcontext['language'] . '/General.php')) { return throw_error(Lang::getTxt('error_lang_general_missing', ['lang' => $upcontext['language'], 'url' => $upgradeurl])); } if (!isset($_GET['skiplang'])) { - $temp = substr(@implode('', @file(Config::$languagesdir . '/' . $upcontext['language'] . '/General.php')), 0, 4096); + $temp = substr(@implode('', @file($lang_dir . '/' . $upcontext['language'] . '/General.php')), 0, 4096); preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*General(?:[\s]{2}|\*/)~i', $temp, $match); @@ -1059,16 +1070,12 @@ function WelcomeLogin() Config::updateSettingsFile(['language' => $new_locale]); } - if (empty(Config::$languagesdir)) { - Config::updateSettingsFile(['languagesdir' => Config::$boarddir . '/Languages']); - } - if (!makeFilesWritable($writable_files)) { return false; } // Check agreement.txt. (it may not exist, in which case $boarddir must be writable.) - if (isset(Config::$modSettings['agreement']) && (!is_writable(Config::$languagesdir) || file_exists(Config::$languagesdir . '/en_US/agreement.txt')) && !is_writable(Config::$languagesdir . '/en_US/agreement.txt')) { + if (isset(Config::$modSettings['agreement']) && (!is_writable($lang_dir) || file_exists($lang_dir . '/en_US/agreement.txt')) && !is_writable($lang_dir . '/en_US/agreement.txt')) { return throw_error(Lang::$txt['error_agreement_not_writable']); } @@ -1388,15 +1395,17 @@ function checkLogin() // This basically is used to match the GET variables to Settings.php. $upcontext['upgrade_status']['pass'] = $upcontext['user']['pass']; + $lang_dir = !empty(Config::$languagesdir) ? Config::$languagesdir : fixRelativePath(Config::$boarddir) . '/Languages'; + // Set the language to that of the user? - if (isset($user_language) && $user_language != $upcontext['language'] && file_exists(Config::$languagesdir . '/' . $upcontext['language'] . '/General.php')) { + if (isset($user_language) && $user_language != $upcontext['language'] && file_exists($lang_dir . '/' . $upcontext['language'] . '/General.php')) { $user_language = basename($user_language, '.lng'); - $temp = substr(@implode('', @file(Config::$languagesdir . '/' . $upcontext['language'] . '/General.php')), 0, 4096); + $temp = substr(@implode('', @file($lang_dir . '/' . $upcontext['language'] . '/General.php')), 0, 4096); preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*General(?:[\s]{2}|\*/)~i', $temp, $match); if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) { $upcontext['upgrade_options_warning'] = Lang::getTxt('warning_lang_old', ['user_language' => $user_language, 'default_language' => $upcontext['language']]); - } elseif (!file_exists(Config::$languagesdir . '/' . $user_language . '/Install.php')) { + } elseif (!file_exists($lang_dir . '/' . $user_language . '/Install.php')) { $upcontext['upgrade_options_warning'] = Lang::getTxt('warning_lang_missing', ['user_language' => $user_language, 'default_language' => $upcontext['language']]); } else { // Set this as the new language. @@ -1547,8 +1556,10 @@ function UpgradeOptions() Config::updateModSettings(['force_ssl' => '1']); } + $lang_dir = !empty(Config::$languagesdir) ? Config::$languagesdir : fixRelativePath(Config::$boarddir) . '/Languages'; + // If we're overriding the language follow it through. - if (isset($upcontext['lang']) && file_exists(Config::$languagesdir . '/' . $upcontext['lang'] . '/General.php')) { + if (isset($upcontext['lang']) && file_exists($lang_dir . '/' . $upcontext['lang'] . '/General.php')) { $changes['language'] = $upcontext['lang']; } @@ -3028,10 +3039,12 @@ function cmdStep0() print_error('Error: Unable to obtain write access to "' . basename(SMF_SETTINGS_BACKUP_FILE) . '".'); } - if (isset(Config::$modSettings['agreement']) && (!is_writable(Config::$languagesdir) || file_exists(Config::$languagesdir . '/en_US/agreement.txt')) && !is_writable(Config::$languagesdir . '/en_US/agreement.txt')) { + $lang_dir = !empty(Config::$languagesdir) ? Config::$languagesdir : fixRelativePath(Config::$boarddir) . '/Languages'; + + if (isset(Config::$modSettings['agreement']) && (!is_writable($lang_dir) || file_exists($lang_dir . '/en_US/agreement.txt')) && !is_writable($lang_dir . '/en_US/agreement.txt')) { print_error('Error: Unable to obtain write access to "agreement.txt".'); } elseif (isset(Config::$modSettings['agreement'])) { - $fp = fopen(Config::$languagesdir . '/en_US/agreement.txt', 'w'); + $fp = fopen($lang_dir . '/en_US/agreement.txt', 'w'); fwrite($fp, Config::$modSettings['agreement']); fclose($fp); } @@ -3064,22 +3077,22 @@ function cmdStep0() print_error('Error: Unable to obtain write access to "db_last_error.php".'); } - if (!file_exists(Config::$languagesdir . '/' . $upcontext['language'] . '/General.php')) { + if (!file_exists($lang_dir . '/' . $upcontext['language'] . '/General.php')) { print_error('Error: Unable to find language files!', true); } else { - $temp = substr(@implode('', @file(Config::$languagesdir . '/' . $upcontext['language'] . '/General.php')), 0, 4096); + $temp = substr(@implode('', @file($lang_dir . '/' . $upcontext['language'] . '/General.php')), 0, 4096); preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match); if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) { print_error('Error: Language files out of date.', true); } - if (!file_exists(Config::$languagesdir . '/' . $upcontext['language'] . '/Install.php')) { + if (!file_exists($lang_dir . '/' . $upcontext['language'] . '/Install.php')) { print_error('Error: Install language is missing for selected language.', true); } // Otherwise include it! - require_once Config::$languagesdir . '/' . $upcontext['language'] . '/Install.php'; + require_once $lang_dir . '/' . $upcontext['language'] . '/Install.php'; } // Do we need to add this setting? From 26c112e0ab7309839ff06de9bd0f1bb964804db2 Mon Sep 17 00:00:00 2001 From: Jon Stovell Date: Sun, 5 May 2024 10:44:12 -0600 Subject: [PATCH 6/6] Changes two incorrect calls to Config::httpsOn() to Sapi::httpsOn() Signed-off-by: Jon Stovell --- other/upgrade.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/other/upgrade.php b/other/upgrade.php index 658c12f0d8..d6416cd3ef 100644 --- a/other/upgrade.php +++ b/other/upgrade.php @@ -905,7 +905,7 @@ function initialize_inputs() deleteFile($upgrade_path . '/Sources/DumpDatabase.php'); deleteFile($upgrade_path . '/Sources/LockTopic.php'); - header('location: http' . (Config::httpsOn() ? 's' : '') . '://' . ($_SERVER['HTTP_HOST'] ?? $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT']) . dirname($_SERVER['PHP_SELF']) . '/Themes/default/images/blank.png'); + header('location: http' . (Sapi::httpsOn() ? 's' : '') . '://' . ($_SERVER['HTTP_HOST'] ?? $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT']) . dirname($_SERVER['PHP_SELF']) . '/Themes/default/images/blank.png'); exit; } @@ -2060,7 +2060,7 @@ function DeleteUpgrade() (new TaskRunner())->runScheduledTasks(['fetchSMfiles']); // Now go get those files! // This is needed in case someone invokes the upgrader using https when upgrading an http forum - if (Config::httpsOn()) { + if (Sapi::httpsOn()) { $settings['default_theme_url'] = strtr($settings['default_theme_url'], ['http://' => 'https://']); } }