X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=classes%2FConfig.php;h=43b99587fa14971c2c66a32790d548da10f4e6c6;hb=7d51cda25d7a056ffdf8e7928b4dfa958597067f;hp=2538a142643f411a21bc0e391221852ee032e52b;hpb=888ed474a161a278579debdb492acc44fbcd7790;p=quix0rs-gnu-social.git diff --git a/classes/Config.php b/classes/Config.php old mode 100755 new mode 100644 index 2538a14264..43b99587fa --- a/classes/Config.php +++ b/classes/Config.php @@ -1,8 +1,31 @@ . + */ + +if (!defined('STATUSNET')) { + exit(1); +} + /** * Table Definition for config */ -require_once 'classes/Memcached_DataObject.php'; + +require_once INSTALLDIR.'/classes/Memcached_DataObject.php'; class Config extends Memcached_DataObject { @@ -19,4 +42,119 @@ class Config extends Memcached_DataObject /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE + + const settingsKey = 'config:settings'; + + static function loadSettings() + { + $settings = self::_getSettings(); + if (!empty($settings)) { + self::_applySettings($settings); + } + } + + static function _getSettings() + { + $c = self::memcache(); + + if (!empty($c)) { + $settings = $c->get(common_cache_key(self::settingsKey)); + if ($settings !== false) { + return $settings; + } + } + + $settings = array(); + + $config = new Config(); + + $config->find(); + + while ($config->fetch()) { + $settings[] = array($config->section, $config->setting, $config->value); + } + + $config->free(); + + if (!empty($c)) { + $c->set(common_cache_key(self::settingsKey), $settings); + } + + return $settings; + } + + static function _applySettings($settings) + { + global $config; + + foreach ($settings as $s) { + list($section, $setting, $value) = $s; + $config[$section][$setting] = $value; + } + } + + function insert() + { + $result = parent::insert(); + if ($result) { + Config::_blowSettingsCache(); + } + return $result; + } + + function delete() + { + $result = parent::delete(); + if ($result) { + Config::_blowSettingsCache(); + } + return $result; + } + + function update($orig=null) + { + $result = parent::update($orig); + if ($result) { + Config::_blowSettingsCache(); + } + return $result; + } + + function pkeyGet($kv) + { + return Memcached_DataObject::pkeyGet('Config', $kv); + } + + static function save($section, $setting, $value) + { + $result = null; + + $config = Config::pkeyGet(array('section' => $section, + 'setting' => $setting)); + + if (!empty($config)) { + $orig = clone($config); + $config->value = $value; + $result = $config->update($orig); + } else { + $config = new Config(); + + $config->section = $section; + $config->setting = $setting; + $config->value = $value; + + $result = $config->insert(); + } + + return $result; + } + + function _blowSettingsCache() + { + $c = self::memcache(); + + if (!empty($c)) { + $c->delete(common_cache_key(self::settingsKey)); + } + } }