]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/Config.php
Merge branch '0.8.x' into 0.9.x
[quix0rs-gnu-social.git] / classes / Config.php
1 <?php
2 /*
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, 2009, Control Yourself, Inc.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 if (!defined('LACONICA')) { exit(1); }
21
22 /**
23  * Table Definition for config
24  */
25
26 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
27
28 class Config extends Memcached_DataObject
29 {
30     ###START_AUTOCODE
31     /* the code below is auto generated do not remove the above tag */
32
33     public $__table = 'config';                          // table name
34     public $section;                         // varchar(32)  primary_key not_null
35     public $setting;                         // varchar(32)  primary_key not_null
36     public $value;                           // varchar(255)
37
38     /* Static get */
39     function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Config',$k,$v); }
40
41     /* the code above is auto generated do not remove the tag below */
42     ###END_AUTOCODE
43
44     const settingsKey = 'config:settings';
45
46     static function loadSettings()
47     {
48         $settings = self::_getSettings();
49         if (!empty($settings)) {
50             self::_applySettings($settings);
51         }
52     }
53
54     static function _getSettings()
55     {
56         $c = self::memcache();
57
58         if (!empty($c)) {
59             $settings = $c->get(common_cache_key(self::settingsKey));
60             if (!empty($settings)) {
61                 return $settings;
62             }
63         }
64
65         $settings = array();
66
67         $config = new Config();
68
69         $config->find();
70
71         while ($config->fetch()) {
72             $settings[] = array($config->section, $config->setting, $config->value);
73         }
74
75         $config->free();
76
77         if (!empty($c)) {
78             $c->set(common_cache_key(self::settingsKey), $settings);
79         }
80
81         return $settings;
82     }
83
84     static function _applySettings($settings)
85     {
86         global $config;
87
88         foreach ($settings as $s) {
89             list($section, $setting, $value) = $s;
90             $config[$section][$setting] = $value;
91         }
92     }
93
94     function insert()
95     {
96         $result = parent::insert();
97         if ($result) {
98             Config::_blowSettingsCache();
99         }
100         return $result;
101     }
102
103     function delete()
104     {
105         $result = parent::delete();
106         if ($result) {
107             Config::_blowSettingsCache();
108         }
109         return $result;
110     }
111
112     function update($orig=null)
113     {
114         $result = parent::update($orig);
115         if ($result) {
116             Config::_blowSettingsCache();
117         }
118         return $result;
119     }
120
121     function _blowSettingsCache()
122     {
123         $c = self::memcache();
124
125         if (!empty($c)) {
126             $c->delete(common_cache_key(self::settingsKey));
127         }
128     }
129 }