From 4dcfb0e9f460ac9e11fc8a4040ac308d951ef84a Mon Sep 17 00:00:00 2001 From: beu Date: Wed, 27 Apr 2022 00:19:41 +0200 Subject: [PATCH] prevent to delete unused settings of other servers --- core/Settings/SettingManager.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/core/Settings/SettingManager.php b/core/Settings/SettingManager.php index 2673afb2..8e93f2a0 100644 --- a/core/Settings/SettingManager.php +++ b/core/Settings/SettingManager.php @@ -129,13 +129,24 @@ class SettingManager implements CallbackListener, UsageInformationAble { */ private function deleteUnusedSettings() { $mysqli = $this->maniaControl->getDatabase()->getMysqli(); - $settingQuery = "DELETE FROM `" . self::TABLE_SETTINGS . "` - WHERE `changed` < NOW() - INTERVAL 1 HOUR;"; - $result = $mysqli->query($settingQuery); + $settingStatement = $mysqli->prepare("DELETE FROM `" . self::TABLE_SETTINGS . "` + WHERE ((`linked` = 1 AND `serverIndex` = ?) OR `linked` = 0) AND `changed` < NOW() - INTERVAL 1 HOUR;"); if ($mysqli->error) { trigger_error($mysqli->error); - return false; + return null; } + + $serverInfo = $this->maniaControl->getServer(); + if ($serverInfo === null) { + return; + } else { + $serverIndex = $serverInfo->index; + } + $settingStatement->bind_param('i', $serverIndex); + if (!$settingStatement->execute()) { + trigger_error('Error executing MySQL query: ' . $settingStatement->error); + } + $result = $settingStatement->get_result(); if ($result) { $this->clearStorage(); return true;