]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/Config/PreloadPConfiguration.php
Merge pull request #7541 from vinzv/patch-2
[friendica.git] / src / Core / Config / PreloadPConfiguration.php
index 1682b7e21bc0b40f3a07dbfefc3fb341928abfea..975a15c50fb19a8c69f56c8685799f4bb6a301a0 100644 (file)
@@ -5,7 +5,7 @@ namespace Friendica\Core\Config;
 use Friendica\Model;
 
 /**
- * This class implements the preload Time configuration, which will cache
+ * This class implements the preload configuration, which will cache
  * all user config values per call in a cache.
  *
  * Minimizes the number of database queries to retrieve configuration values at the cost of memory.
@@ -33,8 +33,8 @@ class PreloadPConfiguration extends PConfiguration
         */
        public function load(int $uid, string $cat = 'config')
        {
-               // Don't load the whole configuration twice
-               if (!empty($this->config_loaded[$uid])) {
+               // Don't load the whole configuration twice or with invalid uid
+               if (!$uid || !empty($this->config_loaded[$uid])) {
                        return;
                }
 
@@ -55,6 +55,10 @@ class PreloadPConfiguration extends PConfiguration
         */
        public function get(int $uid, string $cat, string $key, $default_value = null, bool $refresh = false)
        {
+               if (!$uid) {
+                       return $default_value;
+               }
+
                if (empty($this->config_loaded[$uid])) {
                        $this->load($uid);
                } elseif ($refresh) {
@@ -77,6 +81,10 @@ class PreloadPConfiguration extends PConfiguration
         */
        public function set(int $uid, string $cat, string $key, $value)
        {
+               if (!$uid) {
+                       return false;
+               }
+
                if (empty($this->config_loaded[$uid])) {
                        $this->load($uid);
                }
@@ -99,6 +107,10 @@ class PreloadPConfiguration extends PConfiguration
         */
        public function delete(int $uid, string $cat, string $key)
        {
+               if (!$uid) {
+                       return false;
+               }
+
                if (empty($this->config_loaded[$uid])) {
                        $this->load($uid);
                }