Preserve config.local.php on settings save

Will be helpful when migration from 0.8
This commit is contained in:
slawkens 2023-11-11 14:33:20 +01:00
parent d0590d2747
commit c3c1a6b2a6
2 changed files with 17 additions and 5 deletions

View File

@ -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 = "<?php" . PHP_EOL .
"\$config['installed'] = true;" . PHP_EOL;
$content = "<?php" . PHP_EOL;
unset($config['installed']);
$content .= "\$config['installed'] = true;" . PHP_EOL;
foreach ($config as $key => $value) {
$content .= "\$config['$key'] = ";

View File

@ -1588,7 +1588,13 @@ Sent by MyAAC,<br/>
'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,<br/>
// 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,<br/>
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];
}
}
}