]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/Config.php
BBCode - fixed syntax error
[friendica.git] / src / Core / Config.php
index bff5d81ff07641bac22a6fa1f8238e73f5d3a989..755dc6ebbcf50bfcc82e9f31a7877ea5d89ea8e3 100644 (file)
@@ -8,10 +8,8 @@
  */
 namespace Friendica\Core;
 
+use Friendica\App;
 use Friendica\BaseObject;
-use Friendica\Core\Config;
-
-require_once 'include/dba.php';
 
 /**
  * @brief Arbitrary system configuration storage
@@ -23,15 +21,18 @@ require_once 'include/dba.php';
 class Config extends BaseObject
 {
        /**
-        * @var Friendica\Core\Config\IConfigAdapter
+        * @var \Friendica\Core\Config\IConfigAdapter
         */
        private static $adapter = null;
 
        public static function init()
        {
-               $a = self::getApp();
+               // Database isn't ready or populated yet
+               if (!self::getApp()->getMode()->has(App\Mode::DBCONFIGAVAILABLE)) {
+                       return;
+               }
 
-               if (isset($a->config['system']['config_adapter']) && $a->config['system']['config_adapter'] == 'preload') {
+               if (self::getApp()->getConfigValue('system', 'config_adapter') == 'preload') {
                        self::$adapter = new Config\PreloadConfigAdapter();
                } else {
                        self::$adapter = new Config\JITConfigAdapter();
@@ -47,9 +48,15 @@ class Config extends BaseObject
         * @param string $family The category of the configuration value
         *
         * @return void
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
        public static function load($family = "config")
        {
+               // Database isn't ready or populated yet
+               if (!self::getApp()->getMode()->has(App\Mode::DBCONFIGAVAILABLE)) {
+                       return;
+               }
+
                if (empty(self::$adapter)) {
                        self::init();
                }
@@ -75,9 +82,15 @@ class Config extends BaseObject
         * @param boolean $refresh       optional, If true the config is loaded from the db and not from the cache (default: false)
         *
         * @return mixed Stored value or null if it does not exist
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
        public static function get($family, $key, $default_value = null, $refresh = false)
        {
+               // Database isn't ready or populated yet, fallback to file config
+               if (!self::getApp()->getMode()->has(App\Mode::DBCONFIGAVAILABLE)) {
+                       return self::getApp()->getConfigValue($family, $key, $default_value);
+               }
+
                if (empty(self::$adapter)) {
                        self::init();
                }
@@ -97,10 +110,16 @@ class Config extends BaseObject
         * @param string $key    The configuration key to set
         * @param mixed  $value  The value to store
         *
-        * @return mixed Stored $value or false if the database update failed
+        * @return bool Operation success
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
        public static function set($family, $key, $value)
        {
+               // Database isn't ready or populated yet
+               if (!self::getApp()->getMode()->has(App\Mode::DBCONFIGAVAILABLE)) {
+                       return false;
+               }
+
                if (empty(self::$adapter)) {
                        self::init();
                }
@@ -118,9 +137,15 @@ class Config extends BaseObject
         * @param string $key    The configuration key to delete
         *
         * @return mixed
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
        public static function delete($family, $key)
        {
+               // Database isn't ready or populated yet
+               if (!self::getApp()->getMode()->has(App\Mode::DBCONFIGAVAILABLE)) {
+                       return false;
+               }
+
                if (empty(self::$adapter)) {
                        self::init();
                }