Add a setting to disable removing unused settings

This commit is contained in:
Beu 2022-04-27 09:49:52 +02:00
parent 33194c44d4
commit ed4e2b2614

View File

@ -27,6 +27,7 @@ class SettingManager implements CallbackListener, UsageInformationAble {
const CB_SETTING_CHANGED = 'SettingManager.SettingChanged'; const CB_SETTING_CHANGED = 'SettingManager.SettingChanged';
const SETTING_ALLOW_UNLINK_SERVER = 'Allow to unlink settings with multiple servers'; const SETTING_ALLOW_UNLINK_SERVER = 'Allow to unlink settings with multiple servers';
const SETTING_DELETE_UNUSED_SETTING_AT_START = 'Delete unused settings at ManiaControl start';
/* /*
* Private properties * Private properties
@ -49,6 +50,7 @@ class SettingManager implements CallbackListener, UsageInformationAble {
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::AFTERINIT, $this, 'handleAfterInit'); $this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::AFTERINIT, $this, 'handleAfterInit');
$this->initSetting($this, self::SETTING_ALLOW_UNLINK_SERVER, false); $this->initSetting($this, self::SETTING_ALLOW_UNLINK_SERVER, false);
$this->initSetting($this, self::SETTING_DELETE_UNUSED_SETTING_AT_START, true);
} }
/** /**
@ -128,6 +130,10 @@ class SettingManager implements CallbackListener, UsageInformationAble {
* @return bool * @return bool
*/ */
private function deleteUnusedSettings() { private function deleteUnusedSettings() {
if ($this->getSettingValue($this, self::SETTING_DELETE_UNUSED_SETTING_AT_START)) {
return;
}
$mysqli = $this->maniaControl->getDatabase()->getMysqli(); $mysqli = $this->maniaControl->getDatabase()->getMysqli();
$settingStatement = $mysqli->prepare("DELETE FROM `" . self::TABLE_SETTINGS . "` $settingStatement = $mysqli->prepare("DELETE FROM `" . self::TABLE_SETTINGS . "`
WHERE ((`linked` = 0 AND `serverIndex` = ?) OR `linked` = 1) AND `changed` < NOW() - INTERVAL 1 HOUR;"); WHERE ((`linked` = 0 AND `serverIndex` = ?) OR `linked` = 1) AND `changed` < NOW() - INTERVAL 1 HOUR;");