]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/Config/Adapter/PreloadConfigAdapter.php
Merge branch 'master' into develop
[friendica.git] / src / Core / Config / Adapter / PreloadConfigAdapter.php
index 8cad5c5557441d8dc932b615ad6d283bd4eb8577..c691c88bc53615a3ba14526c142786a9905191fe 100644 (file)
@@ -32,13 +32,16 @@ class PreloadConfigAdapter extends AbstractDbaConfigAdapter implements IConfigAd
 
                $configs = DBA::select('config', ['cat', 'v', 'k']);
                while ($config = DBA::fetch($configs)) {
-                       $return[$config['k']] = $config['v'];
+                       $value = $this->toConfigValue($config['v']);
+                       if (isset($value)) {
+                               $return[$config['cat']][$config['k']] = $value;
+                       }
                }
                DBA::close($configs);
 
                $this->config_loaded = true;
 
-               return [$cat => $return];
+               return $return;
        }
 
        /**
@@ -52,14 +55,14 @@ class PreloadConfigAdapter extends AbstractDbaConfigAdapter implements IConfigAd
 
                $config = DBA::selectFirst('config', ['v'], ['cat' => $cat, 'k' => $key]);
                if (DBA::isResult($config)) {
-                       // manage array value
-                       $value = (preg_match("|^a:[0-9]+:{.*}$|s", $config['v']) ? unserialize($config['v']) : $config['v']);
+                       $value = $this->toConfigValue($config['v']);
 
-                       return $value;
-               } else {
-
-                       return '!<unset>!';
+                       if (isset($value)) {
+                               return $value;
+                       }
                }
+
+               return null;
        }
 
        /**
@@ -75,17 +78,15 @@ class PreloadConfigAdapter extends AbstractDbaConfigAdapter implements IConfigAd
                // So we have to do the conversion here so that the compare below works.
                // The exception are array values.
                $compare_value = !is_array($value) ? (string)$value : $value;
+               $stored_value = $this->get($cat, $key);
 
-               if ($this->get($cat, $key) === $compare_value) {
+               if (isset($stored_value) && $stored_value === $compare_value) {
                        return true;
                }
 
-               // manage array value
-               $dbvalue = is_array($value) ? serialize($value) : $value;
-
-               $result = DBA::update('config', ['v' => $dbvalue], ['cat' => $cat, 'k' => $key], true);
+               $dbvalue = $this->toDbValue($value);
 
-               return $result;
+               return DBA::update('config', ['v' => $dbvalue], ['cat' => $cat, 'k' => $key], true);
        }
 
        /**
@@ -97,8 +98,18 @@ class PreloadConfigAdapter extends AbstractDbaConfigAdapter implements IConfigAd
                        return false;
                }
 
-               $result = DBA::delete('config', ['cat' => $cat, 'k' => $key]);
+               return DBA::delete('config', ['cat' => $cat, 'k' => $key]);
+       }
+
+       /**
+        * {@inheritdoc}
+        */
+       public function isLoaded($cat, $key)
+       {
+               if (!$this->isConnected()) {
+                       return false;
+               }
 
-               return $result;
+               return $this->config_loaded;
        }
 }