3 namespace Friendica\Core\Config;
8 * This class is responsible for all system-wide configuration values in Friendica
9 * There are two types of storage
10 * - The Config-Files (loaded into the FileCache @see Cache\ConfigCache )
11 * - The Config-DB-Table (per Config-DB-model @see Model\Config\Config )
13 class JitConfiguration extends Configuration
19 * @param Cache\ConfigCache $configCache The configuration cache (based on the config-files)
20 * @param Model\Config\Config $configModel The configuration model
22 public function __construct(Cache\ConfigCache $configCache, Model\Config\Config $configModel)
24 parent::__construct($configCache, $configModel);
27 // take the values of the given cache instead of loading them from the model again
28 $preSet = $configCache->getAll();
29 if (!empty($preSet)) {
30 foreach ($preSet as $cat => $data) {
31 foreach ($data as $key => $value) {
32 $this->in_db[$cat][$key] = true;
44 public function load(string $cat = 'config')
46 // If not connected, do nothing
47 if (!$this->configModel->isConnected()) {
51 $config = $this->configModel->load($cat);
53 if (!empty($config[$cat])) {
54 foreach ($config[$cat] as $key => $value) {
55 $this->in_db[$cat][$key] = true;
59 // load the whole category out of the DB into the cache
60 $this->configCache->load($config, true);
66 public function get(string $cat, string $key, $default_value = null, bool $refresh = false)
68 // if the value isn't loaded or refresh is needed, load it to the cache
69 if ($this->configModel->isConnected() &&
70 (empty($this->in_db[$cat][$key]) ||
73 $dbvalue = $this->configModel->get($cat, $key);
75 if (isset($dbvalue)) {
76 $this->configCache->set($cat, $key, $dbvalue);
78 $this->in_db[$cat][$key] = true;
82 // use the config cache for return
83 $result = $this->configCache->get($cat, $key);
85 return (isset($result)) ? $result : $default_value;
91 public function set(string $cat, string $key, $value)
93 // set the cache first
94 $cached = $this->configCache->set($cat, $key, $value);
96 // If there is no connected adapter, we're finished
97 if (!$this->configModel->isConnected()) {
101 $stored = $this->configModel->set($cat, $key, $value);
103 $this->in_db[$cat][$key] = $stored;
105 return $cached && $stored;
109 * @brief Deletes the given key from the system configuration.
111 * Removes the configured value from the stored cache in $this->configCache
112 * (@param string $cat The category of the configuration value
114 * @param string $key The configuration key to delete
117 * @see ConfigCache ) and removes it from the database (@see IConfigAdapter ).
120 public function delete(string $cat, string $key)
122 $cacheRemoved = $this->configCache->delete($cat, $key);
124 if (isset($this->in_db[$cat][$key])) {
125 unset($this->in_db[$cat][$key]);
128 if (!$this->configModel->isConnected()) {
129 return $cacheRemoved;
132 $storeRemoved = $this->configModel->delete($cat, $key);
134 return $cacheRemoved || $storeRemoved;