improved setting manager + setting caching

This commit is contained in:
Steffen Schröder 2014-04-30 02:27:17 +02:00
parent ba41cb3456
commit 471fc1dd79

View File

@ -178,7 +178,7 @@ class SettingManager implements CallbackListener {
* @return bool
*/
public function initSetting($object, $settingName, $default) {
if ($default === null || is_object($default)) {
if (is_null($default) || is_object($default)) {
return false;
}
$className = $this->getClassName($object);
@ -298,6 +298,9 @@ class SettingManager implements CallbackListener {
*/
public function setSetting($object, $settingName, $value) {
$className = $this->getClassName($object);
var_dump($className, $settingName, $value);
$mysqli = $this->maniaControl->database->mysqli;
$settingQuery = "UPDATE `" . self::TABLE_SETTINGS . "`
SET `value` = ?
@ -308,8 +311,8 @@ class SettingManager implements CallbackListener {
trigger_error($mysqli->error);
return false;
}
$value = $this->formatSetting($value);
$settingStatement->bind_param('sss', $value, $className, $settingName);
$setting = $this->formatSetting($value);
$settingStatement->bind_param('sss', $setting, $className, $settingName);
$success = $settingStatement->execute();
if ($settingStatement->error) {
trigger_error($settingStatement->error);
@ -318,10 +321,7 @@ class SettingManager implements CallbackListener {
}
$settingStatement->close();
//FIXME store changed value
if (isset($this->storedSettings[$className . $settingName])) {
unset($this->storedSettings[$className . $settingName]);
}
$this->storedSettings[$className . $settingName] = $value;
// Trigger settings changed Callback
$this->maniaControl->callbackManager->triggerCallback(self::CB_SETTINGS_CHANGED, $className, $settingName, $value);
@ -355,6 +355,9 @@ class SettingManager implements CallbackListener {
return false;
}
$settingStatement->close();
if (isset($this->storedSettings[$className . $settingName])) {
unset($this->storedSettings[$className . $settingName]);
}
return $success;
}
@ -384,6 +387,9 @@ class SettingManager implements CallbackListener {
return false;
}
$settingStatement->close();
if (isset($this->storedSettings[$className . $settingName])) {
unset($this->storedSettings[$className . $settingName]);
}
return $success;
}
@ -454,6 +460,7 @@ class SettingManager implements CallbackListener {
return false;
}
$settingStatement->close();
$this->storedSettings = array();
return $success;
}
}