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 foreach ($config[$cat] as $key => $value) {
54 $this->in_db[$cat][$key] = true;
57 // load the whole category out of the DB into the cache
58 $this->configCache->load($config, true);
64 public function get(string $cat, string $key, $default_value = null, bool $refresh = false)
66 // if the value isn't loaded or refresh is needed, load it to the cache
67 if ($this->configModel->isConnected() &&
68 (empty($this->in_db[$cat][$key]) ||
71 $dbvalue = $this->configModel->get($cat, $key);
73 if (isset($dbvalue)) {
74 $this->configCache->set($cat, $key, $dbvalue);
76 $this->in_db[$cat][$key] = true;
80 // use the config cache for return
81 $result = $this->configCache->get($cat, $key);
83 return (isset($result)) ? $result : $default_value;
89 public function set(string $cat, string $key, $value)
91 // set the cache first
92 $cached = $this->configCache->set($cat, $key, $value);
94 // If there is no connected adapter, we're finished
95 if (!$this->configModel->isConnected()) {
99 $stored = $this->configModel->set($cat, $key, $value);
101 $this->in_db[$cat][$key] = $stored;
103 return $cached && $stored;
107 * @brief Deletes the given key from the system configuration.
109 * Removes the configured value from the stored cache in $this->configCache
110 * (@param string $cat The category of the configuration value
112 * @param string $key The configuration key to delete
115 * @see ConfigCache ) and removes it from the database (@see IConfigAdapter ).
118 public function delete(string $cat, string $key)
120 $cacheRemoved = $this->configCache->delete($cat, $key);
122 if (isset($this->in_db[$cat][$key])) {
123 unset($this->in_db[$cat][$key]);
126 if (!$this->configModel->isConnected()) {
127 return $cacheRemoved;
130 $storeRemoved = $this->configModel->delete($cat, $key);
132 return $cacheRemoved || $storeRemoved;