diff --git a/Sources/Config.php b/Sources/Config.php index f9f542e683..a2f347f13b 100644 --- a/Sources/Config.php +++ b/Sources/Config.php @@ -249,11 +249,15 @@ class Config ######### Modification Support ######### /** - * @var bool + * @var int * - * Master switch to enable backward compatibility behaviours. + * Master switch to enable backward compatibility behaviours: + * 0: Off. This is the default. + * 1: On. This will be set automatically if an installed modification needs it. + * 2: Forced on. Use this to enable backward compatibility behaviours even when + * no installed modifications require them. This is usually not necessary. */ - public static bool $backward_compatibility = true; + public static int $backward_compatibility; ######### Legacy settings ######### /** @@ -783,13 +787,17 @@ class Config ######### Modification Support ######### /** - * @var bool + * @var int * - * Master switch to enable backward compatibility behaviours. + * Master switch to enable backward compatibility behaviours: + * 0: Off. This is the default. + * 1: On. This will be set automatically if an installed modification needs it. + * 2: Forced on. Use this to enable backward compatibility behaviours even when + * no installed modifications require them. This is usually not necessary. */ END, - 'default' => true, - 'type' => 'boolean', + 'default' => 0, + 'type' => 'integer', ], 'db_character_set' => [ 'text' => <<<'END' @@ -956,7 +964,7 @@ public static function set(array $settings): void // For backward compatibility, make settings available as global variables. // Must do this manually because SMF\BackwardCompatibility is not loaded yet. - if (self::$backward_compatibility && !self::$exported) { + if (!empty(self::$backward_compatibility) && !self::$exported) { foreach ($settings as $var => $val) { if (property_exists(__CLASS__, $var)) { $GLOBALS[$var] = &self::${$var}; diff --git a/Sources/PackageManager/PackageManager.php b/Sources/PackageManager/PackageManager.php index 72e29f1e94..7dc26f85d1 100644 --- a/Sources/PackageManager/PackageManager.php +++ b/Sources/PackageManager/PackageManager.php @@ -1412,6 +1412,50 @@ public function install(): void // Restore file permissions? SubsPackage::create_chmod_control([], [], true); + + // Does Config::$backward_compatibility need to be updated? + $this->updateBackwardCompatibility(); + } + + /** + * Enables Config::$backward_compatibility if it is needed. + * + * Once support for backward compatibility behaviours has been discontinued + * in a future version of SMF, this method can be removed. + */ + public function updateBackwardCompatibility(): void + { + // If it has been forced on, leave it alone. + if ((Config::$backward_compatibility ?? null) === 2) { + return; + } + + $min_version = preg_replace('/^(\d+\.\d+).*/', '$1.dev.0', SMF_VERSION); + + $request = Db::$db->query( + '', + 'SELECT smf_version + FROM {db_prefix}log_packages + WHERE install_state != {int:not_installed} + ORDER BY smf_version ASC', + [ + 'not_installed' => 0, + ], + ); + + while ($row = Db::$db->fetch_assoc($request)) { + $row['smf_version'] = strtr(strtolower($row['smf_version']), ' ', '.'); + + if (version_compare($row['smf_version'], $min_version, '<')) { + break; + } + } + + Db::$db->free_result($request); + + Config::updateSettingsFile([ + 'backward_compatibility' => version_compare($row['smf_version'], $min_version, '<'), + ]); } /** diff --git a/other/Settings.php b/other/Settings.php index d5557aeffe..3b7e0ccae6 100644 --- a/other/Settings.php +++ b/other/Settings.php @@ -224,11 +224,15 @@ ######### Modification Support ######### /** - * @var bool + * @var int * - * Master switch to enable backward compatibility behaviours. + * Master switch to enable backward compatibility behaviours: + * 0: Off. This is the default. + * 1: On. This will be set automatically if an installed modification needs it. + * 2: Forced on. Use this to enable backward compatibility behaviours even when + * no installed modifications require them. This is usually not necessary. */ -$backward_compatibility = true; +$backward_compatibility = 0; ######### Legacy Settings ######### /** diff --git a/other/Settings_bak.php b/other/Settings_bak.php index d5557aeffe..3b7e0ccae6 100644 --- a/other/Settings_bak.php +++ b/other/Settings_bak.php @@ -224,11 +224,15 @@ ######### Modification Support ######### /** - * @var bool + * @var int * - * Master switch to enable backward compatibility behaviours. + * Master switch to enable backward compatibility behaviours: + * 0: Off. This is the default. + * 1: On. This will be set automatically if an installed modification needs it. + * 2: Forced on. Use this to enable backward compatibility behaviours even when + * no installed modifications require them. This is usually not necessary. */ -$backward_compatibility = true; +$backward_compatibility = 0; ######### Legacy Settings ######### /**