prevent to delete unused settings of other servers

This commit is contained in:
Beu 2022-04-27 00:19:41 +02:00
parent e2483731c4
commit 4dcfb0e9f4

View File

@ -129,13 +129,24 @@ class SettingManager implements CallbackListener, UsageInformationAble {
*/ */
private function deleteUnusedSettings() { private function deleteUnusedSettings() {
$mysqli = $this->maniaControl->getDatabase()->getMysqli(); $mysqli = $this->maniaControl->getDatabase()->getMysqli();
$settingQuery = "DELETE FROM `" . self::TABLE_SETTINGS . "` $settingStatement = $mysqli->prepare("DELETE FROM `" . self::TABLE_SETTINGS . "`
WHERE `changed` < NOW() - INTERVAL 1 HOUR;"; WHERE ((`linked` = 1 AND `serverIndex` = ?) OR `linked` = 0) AND `changed` < NOW() - INTERVAL 1 HOUR;");
$result = $mysqli->query($settingQuery);
if ($mysqli->error) { if ($mysqli->error) {
trigger_error($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) { if ($result) {
$this->clearStorage(); $this->clearStorage();
return true; return true;