X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCore%2FPConfig.php;h=bfa52f5a36ebd7e480d97d2c638ccf8a77b2958e;hb=9665f4ed415d34cbcf09df8c6ca04882303e9544;hp=bf84a4b8f77b417ef3f28208292d1b4d00ee08a7;hpb=10b72b0e9eb0aa2ef1f2c612464ffcbbe4cc02ce;p=friendica.git diff --git a/src/Core/PConfig.php b/src/Core/PConfig.php index bf84a4b8f7..bfa52f5a36 100644 --- a/src/Core/PConfig.php +++ b/src/Core/PConfig.php @@ -1,20 +1,18 @@ config['system']['config_adapter']) && $a->config['system']['config_adapter'] == 'preload') { + self::$adapter = new Config\PreloadPConfigAdapter($uid); + } else { + self::$adapter = new Config\JITPConfigAdapter($uid); + } + } /** * @brief Loads all configuration values of a user's config family into a cached storage. @@ -39,20 +51,11 @@ class PConfig */ public static function load($uid, $family) { - $a = get_app(); - - $r = dba::select('pconfig', array('v', 'k'), array('cat' => $family, 'uid' => $uid)); - if (DBM::is_result($r)) { - while ($rr = dba::fetch($r)) { - $k = $rr['k']; - $a->config[$uid][$family][$k] = $rr['v']; - self::$in_db[$uid][$family][$k] = true; - } - } else if ($family != 'config') { - // Negative caching - $a->config[$uid][$family] = "!!"; + if (empty(self::$adapter)) { + self::init($uid); } - dba::close($r); + + self::$adapter->load($uid, $family); } /** @@ -72,37 +75,11 @@ class PConfig */ public static function get($uid, $family, $key, $default_value = null, $refresh = false) { - $a = get_app(); - - if (!$refresh) { - // Looking if the whole family isn't set - if (isset($a->config[$uid][$family])) { - if ($a->config[$uid][$family] === '!!') { - return $default_value; - } - } - - if (isset($a->config[$uid][$family][$key])) { - if ($a->config[$uid][$family][$key] === '!!') { - return $default_value; - } - return $a->config[$uid][$family][$key]; - } + if (empty(self::$adapter)) { + self::init($uid); } - $ret = dba::select('pconfig', array('v'), array('uid' => $uid, 'cat' => $family, 'k' => $key), array('limit' => 1)); - if (DBM::is_result($ret)) { - $val = (preg_match("|^a:[0-9]+:{.*}$|s", $ret['v']) ? unserialize($ret['v']) : $ret['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 self::$adapter->get($uid, $family, $key, $default_value, $refresh); } /** @@ -122,31 +99,11 @@ class PConfig */ public static function set($uid, $family, $key, $value) { - $a = get_app(); - - // 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); - - $stored = self::get($uid, $family, $key, null, true); - - if (($stored === $dbvalue) && self::$in_db[$uid][$family][$key]) { - return true; + if (empty(self::$adapter)) { + self::init($uid); } - $a->config[$uid][$family][$key] = $dbvalue; - - // manage array value - $dbvalue = (is_array($value) ? serialize($value) : $dbvalue); - - dba::update('pconfig', array('v' => $dbvalue), array('uid' => $uid, 'cat' => $family, 'k' => $key), true); - - if ($ret) { - self::$in_db[$uid][$family][$key] = true; - return $value; - } - return $ret; + return self::$adapter->set($uid, $family, $key, $value); } /** @@ -163,15 +120,10 @@ class PConfig */ public static function delete($uid, $family, $key) { - $a = get_app(); - - if (x($a->config[$uid][$family], $key)) { - unset($a->config[$uid][$family][$key]); - unset(self::$in_db[$uid][$family][$key]); + if (empty(self::$adapter)) { + self::init($uid); } - $ret = dba::delete('pconfig', array('uid' => $uid, 'cat' => $family, 'k' => $key)); - - return $ret; + return self::$adapter->delete($uid, $family, $key); } }