summaryrefslogtreecommitdiff
path: root/classes/Config.php
diff options
context:
space:
mode:
authorEvan Prodromou <evan@controlyourself.ca>2009-08-21 16:14:32 -0400
committerEvan Prodromou <evan@controlyourself.ca>2009-08-21 16:14:32 -0400
commit538dcf2eefd2742f698cb812ae90c10971ef5e75 (patch)
treef73831cc8355cbec6869cbd4ccc54726dba71063 /classes/Config.php
parent888ed474a161a278579debdb492acc44fbcd7790 (diff)
load configuration options from database at runtime
Diffstat (limited to 'classes/Config.php')
-rwxr-xr-xclasses/Config.php109
1 files changed, 108 insertions, 1 deletions
diff --git a/classes/Config.php b/classes/Config.php
index 2538a1426..5bec13fdc 100755
--- a/classes/Config.php
+++ b/classes/Config.php
@@ -1,8 +1,29 @@
<?php
+/*
+ * Laconica - a distributed open-source microblogging tool
+ * Copyright (C) 2008, 2009, Control Yourself, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+if (!defined('LACONICA')) { 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 +40,90 @@ 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 (!empty($settings)) {
+ 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 _blowSettingsCache()
+ {
+ $c = self::memcache();
+
+ if (!empty($c)) {
+ $c->delete(common_cache_key(self::settingsKey));
+ }
+ }
}