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 Managed_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 public static function schemaDef()
50 'section' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'default' => '', 'description' => 'configuration section'),
51 'setting' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'default' => '', 'description' => 'configuration setting'),
52 'value' => array('type' => 'varchar', 'length' => 255, 'description' => 'configuration value'),
54 'primary key' => array('section', 'setting'),
58 const settingsKey = 'config:settings';
60 static function loadSettings()
63 $settings = self::_getSettings();
64 if (!empty($settings)) {
65 self::_applySettings($settings);
67 } catch (Exception $e) {
72 static function _getSettings()
74 $c = self::memcache();
77 $settings = $c->get(Cache::key(self::settingsKey));
78 if ($settings !== false) {
85 $config = new Config();
89 while ($config->fetch()) {
90 $settings[] = array($config->section, $config->setting, $config->value);
96 $c->set(Cache::key(self::settingsKey), $settings);
102 static function _applySettings($settings)
106 foreach ($settings as $s) {
107 list($section, $setting, $value) = $s;
108 $config[$section][$setting] = $value;
114 $result = parent::insert();
116 Config::_blowSettingsCache();
123 $result = parent::delete();
125 Config::_blowSettingsCache();
130 function update($orig=null)
132 $result = parent::update($orig);
134 Config::_blowSettingsCache();
139 function pkeyGet($kv)
141 return Memcached_DataObject::pkeyGet('Config', $kv);
144 static function save($section, $setting, $value)
148 $config = Config::pkeyGet(array('section' => $section,
149 'setting' => $setting));
151 if (!empty($config)) {
152 $orig = clone($config);
153 $config->value = $value;
154 $result = $config->update($orig);
156 $config = new Config();
158 $config->section = $section;
159 $config->setting = $setting;
160 $config->value = $value;
162 $result = $config->insert();
168 function _blowSettingsCache()
170 $c = self::memcache();
173 $c->delete(Cache::key(self::settingsKey));