X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2FCore%2FPConfig.php;h=6ced9fc7553fc6fa1198848c123db0405490f5c9;hb=16d4392573829b5b02db449778cdc4bc4b2e0cbc;hp=63d204b3a2cd01ff63c1b88842ed65d83c1866bf;hpb=126c4774c330d9c9c9038312198c57fb653682df;p=friendica.git diff --git a/include/Core/PConfig.php b/include/Core/PConfig.php index 63d204b3a2..6ced9fc755 100644 --- a/include/Core/PConfig.php +++ b/include/Core/PConfig.php @@ -1,5 +1,8 @@ config[$uid][$family][$k] = $rr['v']; + self::$in_db[$uid][$family][$k] = true; } } else if ($family != 'config') { // Negative caching @@ -65,7 +71,7 @@ class PConfig { */ public static function get($uid, $family, $key, $default_value = null, $refresh = false) { - global $a; + $a = get_app(); if (!$refresh) { // Looking if the whole family isn't set @@ -92,12 +98,15 @@ class PConfig { if (count($ret)) { $val = (preg_match("|^a:[0-9]+:{.*}$|s", $ret[0]['v'])?unserialize( $ret[0]['v']):$ret[0]['v']); $a->config[$uid][$family][$key] = $val; + self::$in_db[$uid][$family][$key] = true; return $val; } else { $a->config[$uid][$family][$key] = '!!'; + self::$in_db[$uid][$family][$key] = false; + + return $default_value; } - return $default_value; } /** @@ -120,20 +129,25 @@ class PConfig { */ public static function set($uid, $family, $key, $value) { - global $a; + $a = get_app(); - $stored = self::get($uid, $family, $key); + // We store our setting values in a string variable. + // So we have to do the conversion here so that the compare below works. + // The exception are array values. + $dbvalue = (!is_array($value) ? (string)$value : $value); - if ($stored == $value) { + $stored = self::get($uid, $family, $key, null, true); + + if (($stored === $dbvalue) AND self::$in_db[$uid][$family][$key]) { return true; } - // manage array value - $dbvalue = (is_array($value) ? serialize($value):$value); + $a->config[$uid][$family][$key] = $dbvalue; - $a->config[$uid][$family][$key] = $value; + // manage array value + $dbvalue = (is_array($value) ? serialize($value) : $dbvalue); - if (is_null($stored)) { + if (is_null($stored) OR !self::$in_db[$uid][$family][$key]) { $ret = q("INSERT INTO `pconfig` (`uid`, `cat`, `k`, `v`) VALUES (%d, '%s', '%s', '%s') ON DUPLICATE KEY UPDATE `v` = '%s'", intval($uid), dbesc($family), @@ -151,6 +165,7 @@ class PConfig { } if ($ret) { + self::$in_db[$uid][$family][$key] = true; return $value; } return $ret; @@ -171,10 +186,11 @@ class PConfig { */ public static function delete($uid,$family,$key) { - global $a; + $a = get_app(); if (x($a->config[$uid][$family], $key)) { unset($a->config[$uid][$family][$key]); + unset(self::$in_db[$uid][$family][$key]); } $ret = q("DELETE FROM `pconfig` WHERE `uid` = %d AND `cat` = '%s' AND `k` = '%s'",