]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/PConfig.php
BBCode - fixed syntax error
[friendica.git] / src / Core / PConfig.php
index bfa52f5a36ebd7e480d97d2c638ccf8a77b2958e..584318adbc65a4c0efa1368940d1d1961f15e649 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 Management of user configuration storage
@@ -23,7 +21,7 @@ require_once 'include/dba.php';
 class PConfig extends BaseObject
 {
        /**
-        * @var Friendica\Core\Config\IPConfigAdapter
+        * @var \Friendica\Core\Config\IPConfigAdapter
         */
        private static $adapter = null;
 
@@ -31,10 +29,15 @@ class PConfig extends BaseObject
        {
                $a = self::getApp();
 
-               if (isset($a->config['system']['config_adapter']) && $a->config['system']['config_adapter'] == 'preload') {
+               // Database isn't ready or populated yet
+               if (!$a->getMode()->has(App\Mode::DBCONFIGAVAILABLE)) {
+                       return;
+               }
+
+               if ($a->getConfigValue('system', 'config_adapter') == 'preload') {
                        self::$adapter = new Config\PreloadPConfigAdapter($uid);
                } else {
-                       self::$adapter = new Config\JITPConfigAdapter($uid);
+                       self::$adapter = new Config\JITPConfigAdapter();
                }
        }
 
@@ -48,9 +51,15 @@ class PConfig extends BaseObject
         * @param string $family The category of the configuration value
         *
         * @return void
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
        public static function load($uid, $family)
        {
+               // Database isn't ready or populated yet
+               if (!self::getApp()->getMode()->has(App\Mode::DBCONFIGAVAILABLE)) {
+                       return;
+               }
+
                if (empty(self::$adapter)) {
                        self::init($uid);
                }
@@ -72,9 +81,15 @@ class PConfig 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($uid, $family, $key, $default_value = null, $refresh = false)
        {
+               // Database isn't ready or populated yet
+               if (!self::getApp()->getMode()->has(App\Mode::DBCONFIGAVAILABLE)) {
+                       return;
+               }
+
                if (empty(self::$adapter)) {
                        self::init($uid);
                }
@@ -88,17 +103,23 @@ class PConfig extends BaseObject
         * Stores a config value ($value) in the category ($family) under the key ($key)
         * for the user_id $uid.
         *
-        * @note Please do not store booleans - convert to 0/1 integer values!
+        * @note  Please do not store booleans - convert to 0/1 integer values!
         *
         * @param string $uid    The user_id
         * @param string $family The category of the configuration value
         * @param string $key    The configuration key to set
-        * @param string $value  The value to store
+        * @param mixed  $value  The value to store
         *
-        * @return mixed Stored $value or false
+        * @return bool Operation success
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
        public static function set($uid, $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($uid);
                }
@@ -117,9 +138,15 @@ class PConfig extends BaseObject
         * @param string $key    The configuration key to delete
         *
         * @return mixed
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
        public static function delete($uid, $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($uid);
                }