]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/Config/Adapter/PreloadPConfigAdapter.php
Merge branch 'master' into develop
[friendica.git] / src / Core / Config / Adapter / PreloadPConfigAdapter.php
index 72266744f24264f41f6a1c94fadf9f5cc1f4ec8e..838f3763dfcd5f26849b3c915bbbd1baa957696b 100644 (file)
@@ -25,11 +25,11 @@ class PreloadPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfig
        {
                parent::__construct();
 
+               $this->config_loaded = [];
+
                if (isset($uid)) {
                        $this->load($uid, 'config');
                }
-
-               $this->config_loaded = [];
        }
 
        /**
@@ -43,17 +43,15 @@ class PreloadPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfig
                        return $return;
                }
 
-               if ($this->isLoaded($uid, $cat, null)) {
+               if (!$this->isLoaded($uid, $cat, null)) {
                        return $return;
                }
 
                $pconfigs = DBA::select('pconfig', ['cat', 'v', 'k'], ['uid' => $uid]);
                while ($pconfig = DBA::fetch($pconfigs)) {
-                       $value = $pconfig['v'];
-                       if (isset($value) && $value !== '') {
+                       $value = $this->toConfigValue($pconfig['v']);
+                       if (isset($value)) {
                                $return[$pconfig['cat']][$pconfig['k']] = $value;
-                       } else {
-                               $return[$pconfig['cat']][$pconfig['k']] = '!<unset>!';
                        }
                }
                DBA::close($pconfigs);
@@ -69,7 +67,7 @@ class PreloadPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfig
        public function get($uid, $cat, $key)
        {
                if (!$this->isConnected()) {
-                       return '!<unset>!';
+                       return null;
                }
 
                if (!$this->isLoaded($uid, $cat, $key)) {
@@ -78,14 +76,13 @@ class PreloadPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfig
 
                $config = DBA::selectFirst('pconfig', ['v'], ['uid' => $uid, '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']);
 
-                       if (isset($value) && $value !== '') {
+                       if (isset($value)) {
                                return $value;
                        }
                }
-               return '!<unset>!';
+               return null;
        }
 
        /**
@@ -97,24 +94,22 @@ class PreloadPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfig
                        return false;
                }
 
-               if ($this->isLoaded($uid, $cat, $key)) {
+               if (!$this->isLoaded($uid, $cat, $key)) {
                        $this->load($uid, $cat);
                }
                // We store our setting values as strings.
                // 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($uid, $cat, $key);
 
-               if ($this->get($uid, $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('pconfig', ['v' => $dbvalue], ['uid' => $uid, 'cat' => $cat, 'k' => $key], true);
+               $dbvalue = $this->toDbValue($value);
 
-               return $result;
+               return DBA::update('pconfig', ['v' => $dbvalue], ['uid' => $uid, 'cat' => $cat, 'k' => $key], true);
        }
 
        /**
@@ -130,9 +125,7 @@ class PreloadPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfig
                        $this->load($uid, $cat);
                }
 
-               $result = DBA::delete('pconfig', ['uid' => $uid, 'cat' => $cat, 'k' => $key]);
-
-               return $result;
+               return DBA::delete('pconfig', ['uid' => $uid, 'cat' => $cat, 'k' => $key]);
        }
 
        /**