3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2008, 2009, Control Yourself, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('STATUSNET')) {
25 * Table Definition for config
28 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
30 class Config extends Memcached_DataObject
33 /* the code below is auto generated do not remove the above tag */
35 public $__table = 'config'; // table name
36 public $section; // varchar(32) primary_key not_null
37 public $setting; // varchar(32) primary_key not_null
38 public $value; // varchar(255)
41 function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Config',$k,$v); }
43 /* the code above is auto generated do not remove the tag below */
46 const settingsKey = 'config:settings';
48 static function loadSettings()
50 $settings = self::_getSettings();
51 if (!empty($settings)) {
52 self::_applySettings($settings);
56 static function _getSettings()
58 $c = self::memcache();
61 $settings = $c->get(common_cache_key(self::settingsKey));
62 if (!empty($settings)) {
69 $config = new Config();
73 while ($config->fetch()) {
74 $settings[] = array($config->section, $config->setting, $config->value);
80 $c->set(common_cache_key(self::settingsKey), $settings);
86 static function _applySettings($settings)
90 foreach ($settings as $s) {
91 list($section, $setting, $value) = $s;
92 $config[$section][$setting] = $value;
98 $result = parent::insert();
100 Config::_blowSettingsCache();
107 $result = parent::delete();
109 Config::_blowSettingsCache();
114 function update($orig=null)
116 $result = parent::update($orig);
118 Config::_blowSettingsCache();
123 function &pkeyGet($kv)
125 return Memcached_DataObject::pkeyGet('Config', $kv);
128 static function save($section, $setting, $value)
132 $config = Config::pkeyGet(array('section' => $section,
133 'setting' => $setting));
135 if (!empty($config)) {
136 $orig = clone($config);
137 $config->value = $value;
138 $result = $config->update($orig);
140 $config = new Config();
142 $config->section = $section;
143 $config->setting = $setting;
144 $config->value = $value;
146 $result = $config->insert();
152 function _blowSettingsCache()
154 $c = self::memcache();
157 $c->delete(common_cache_key(self::settingsKey));