From c3c1a6b2a60a5fdfb025103d009db1ec5e855833 Mon Sep 17 00:00:00 2001 From: slawkens Date: Sat, 11 Nov 2023 14:33:20 +0100 Subject: [PATCH] Preserve config.local.php on settings save Will be helpful when migration from 0.8 --- system/libs/Settings.php | 10 ++++++++-- system/settings.php | 12 +++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/system/libs/Settings.php b/system/libs/Settings.php index 86b2b41b..bfa85237 100644 --- a/system/libs/Settings.php +++ b/system/libs/Settings.php @@ -129,6 +129,9 @@ class Settings implements ArrayAccess if (is_bool($value)) { $settingsDb[$key] = $value ? 'true' : 'false'; } + elseif (is_array($value)) { + $settingsDb[$key] = $value; + } else { $settingsDb[$key] = (string)$value; } @@ -530,8 +533,11 @@ class Settings implements ArrayAccess public static function saveConfig($config, $filename, &$content = '') { - $content = " $value) { $content .= "\$config['$key'] = "; diff --git a/system/settings.php b/system/settings.php index d95e16d7..26245ea3 100644 --- a/system/settings.php +++ b/system/settings.php @@ -1588,7 +1588,13 @@ Sent by MyAAC,
'beforeSave' => function(&$settings, &$values) { global $config; - $configToSave = []; + $configOriginal = $config; + unset($config); + + $config = []; + require BASE . 'config.local.php'; + + $configToSave = $config; $server_path = ''; $database = []; @@ -1625,7 +1631,7 @@ Sent by MyAAC,
// if fail - revert the setting and inform the user if (!file_exists($server_path . 'config.lua')) { error('Server Path is invalid - cannot find config.lua in the directory. Setting have been reverted.'); - $configToSave['server_path'] = $config['server_path']; + $configToSave['server_path'] = $configOriginal['server_path']; } // test database connection @@ -1633,7 +1639,7 @@ Sent by MyAAC,
if ($database['database_overwrite'] && !Settings::testDatabaseConnection($database)) { foreach ($database as $key => $value) { if (!in_array($key, ['database_log', 'database_persistent'])) { // ignore these two - $configToSave[$key] = $config[$key]; + $configToSave[$key] = $configOriginal[$key]; } } }