]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/Config/Adapter/JITPConfigAdapter.php
Merge branch 'master' into develop
[friendica.git] / src / Core / Config / Adapter / JITPConfigAdapter.php
index 950dd58bd8ff216c9b283b19eef0859ce5540aba..a0c6a9547fdc46bf83b512853f7824e3a71d0a1e 100644 (file)
@@ -29,14 +29,18 @@ class JITPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfigAdap
                if (DBA::isResult($pconfigs)) {
                        while ($pconfig = DBA::fetch($pconfigs)) {
                                $key = $pconfig['k'];
+                               $value = $this->toConfigValue($pconfig['v']);
 
-                               $return[$key] = $pconfig['v'];
-
+                               // The value was in the db, so don't check it again (unless you have to)
                                $this->in_db[$uid][$cat][$key] = true;
+
+                               if (isset($value)) {
+                                       $return[$key] = $value;
+                               }
                        }
                } else if ($cat != 'config') {
                        // Negative caching
-                       $return[null] = "!<unset>!";
+                       $return = null;
                }
                DBA::close($pconfigs);
 
@@ -45,25 +49,31 @@ class JITPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfigAdap
 
        /**
         * {@inheritdoc}
+        *
+        * @param bool $mark if true, mark the selection of the current cat/key pair
         */
-       public function get($uid, $cat, $key)
+       public function get($uid, $cat, $key, $mark = true)
        {
                if (!$this->isConnected()) {
                        return null;
                }
 
+               // The value was in the db, so don't check it again (unless you have to)
+               if ($mark) {
+                       $this->in_db[$uid][$cat][$key] = true;
+               }
+
                $pconfig = DBA::selectFirst('pconfig', ['v'], ['uid' => $uid, 'cat' => $cat, 'k' => $key]);
                if (DBA::isResult($pconfig)) {
-                       // manage array value
-                       $value = (preg_match("|^a:[0-9]+:{.*}$|s", $pconfig['v']) ? unserialize($pconfig['v']) : $pconfig['v']);
+                       $value = $this->toConfigValue($pconfig['v']);
 
-                       $this->in_db[$uid][$cat][$key] = true;
-                       return $value;
-               } else {
-
-                       $this->in_db[$uid][$cat][$key] = false;
-                       return '!<unset>!';
+                       if (isset($value)) {
+                               return $value;
+                       }
                }
+
+               $this->in_db[$uid][$cat][$key] = false;
+               return null;
        }
 
        /**
@@ -78,9 +88,8 @@ class JITPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfigAdap
                // We store our setting values in a string variable.
                // So we have to do the conversion here so that the compare below works.
                // The exception are array values.
-               $dbvalue = (!is_array($value) ? (string)$value : $value);
-
-               $stored = $this->get($uid, $cat, $key);
+               $compare_value = (!is_array($value) ? (string)$value : $value);
+               $stored_value = $this->get($uid, $cat, $key, false);
 
                if (!isset($this->in_db[$uid])) {
                        $this->in_db[$uid] = [];
@@ -92,12 +101,12 @@ class JITPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfigAdap
                        $this->in_db[$uid][$cat][$key] = false;
                }
 
-               if (($stored === $dbvalue) && $this->in_db[$uid][$cat][$key]) {
+               if (isset($stored_value) && ($stored_value === $compare_value) && $this->in_db[$uid][$cat][$key]) {
                        return true;
                }
 
                // manage array value
-               $dbvalue = (is_array($value) ? serialize($value) : $dbvalue);
+               $dbvalue = (is_array($value) ? serialize($value) : $value);
 
                $result = DBA::update('pconfig', ['v' => $dbvalue], ['uid' => $uid, 'cat' => $cat, 'k' => $key], true);
 
@@ -115,12 +124,22 @@ class JITPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfigAdap
                        return false;
                }
 
-               if (!empty($this->in_db[$uid][$cat][$key])) {
+               if (isset($this->in_db[$uid][$cat][$key])) {
                        unset($this->in_db[$uid][$cat][$key]);
                }
 
-               $result = DBA::delete('pconfig', ['uid' => $uid, 'cat' => $cat, 'k' => $key]);
+               return DBA::delete('pconfig', ['uid' => $uid, 'cat' => $cat, 'k' => $key]);
+       }
 
-               return $result;
+       /**
+        * {@inheritdoc}
+        */
+       public function isLoaded($uid, $cat, $key)
+       {
+               if (!$this->isConnected()) {
+                       return false;
+               }
+
+               return (isset($this->in_db[$uid][$cat][$key])) && $this->in_db[$uid][$cat][$key];
        }
 }