]> git.mxchange.org Git - friendica.git/commitdiff
fixing preload adapter
authorPhilipp Holzer <admin@philipp.info>
Fri, 22 Feb 2019 23:23:41 +0000 (00:23 +0100)
committerPhilipp Holzer <admin@philipp.info>
Fri, 22 Feb 2019 23:23:41 +0000 (00:23 +0100)
src/Core/Config/Adapter/JITConfigAdapter.php
src/Core/Config/Adapter/JITPConfigAdapter.php
src/Core/Config/Adapter/PreloadConfigAdapter.php
src/Core/Config/Adapter/PreloadPConfigAdapter.php

index 5a41463036b2cfbfd18777f0aa4c4c73398efd0b..d125f7d40048c5dacedff2a5fb44c56808d22086 100644 (file)
@@ -67,7 +67,6 @@ class JITConfigAdapter extends AbstractDbaConfigAdapter implements IConfigAdapte
 
                $config = DBA::selectFirst('config', ['v'], ['cat' => $cat, 'k' => $key]);
                if (DBA::isResult($config)) {
-                       // manage array value
                        $value = $this->toConfigValue($config['v']);
 
                        // just return it in case it is set
@@ -91,9 +90,8 @@ class JITConfigAdapter extends AbstractDbaConfigAdapter implements IConfigAdapte
                // 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($cat, $key, false);
+               $compare_value = (!is_array($value) ? (string)$value : $value);
+               $stored_value = $this->get($cat, $key, false);
 
                if (!isset($this->in_db[$cat])) {
                        $this->in_db[$cat] = [];
@@ -102,11 +100,11 @@ class JITConfigAdapter extends AbstractDbaConfigAdapter implements IConfigAdapte
                        $this->in_db[$cat][$key] = false;
                }
 
-               if (isset($stored) && ($stored === $dbvalue) && $this->in_db[$cat][$key]) {
+               if (isset($stored_value) && ($stored_value === $compare_value) && $this->in_db[$cat][$key]) {
                        return true;
                }
 
-               $dbvalue = $this->toDbValue($dbvalue);
+               $dbvalue = $this->toDbValue($value);
 
                $result = DBA::update('config', ['v' => $dbvalue], ['cat' => $cat, 'k' => $key], true);
 
index 5c1627eba009175ca17821c8050200cdf9d30201..a0c6a9547fdc46bf83b512853f7824e3a71d0a1e 100644 (file)
@@ -88,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, false);
+               $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] = [];
@@ -102,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);
 
index d9f7b132d33b3224f83f9534dd0962ccfbbc5e73..c691c88bc53615a3ba14526c142786a9905191fe 100644 (file)
@@ -32,7 +32,7 @@ class PreloadConfigAdapter extends AbstractDbaConfigAdapter implements IConfigAd
 
                $configs = DBA::select('config', ['cat', 'v', 'k']);
                while ($config = DBA::fetch($configs)) {
-                       $value = $config['v'];
+                       $value = $this->toConfigValue($config['v']);
                        if (isset($value)) {
                                $return[$config['cat']][$config['k']] = $value;
                        }
@@ -55,8 +55,7 @@ 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']);
 
                        if (isset($value)) {
                                return $value;
@@ -79,13 +78,13 @@ 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;
+               $dbvalue = $this->toDbValue($value);
 
                return DBA::update('config', ['v' => $dbvalue], ['cat' => $cat, 'k' => $key], true);
        }
index 1af526b7c19c40644cad8db10b9dfd662bfa1f04..838f3763dfcd5f26849b3c915bbbd1baa957696b 100644 (file)
@@ -49,7 +49,7 @@ class PreloadPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfig
 
                $pconfigs = DBA::select('pconfig', ['cat', 'v', 'k'], ['uid' => $uid]);
                while ($pconfig = DBA::fetch($pconfigs)) {
-                       $value = $pconfig['v'];
+                       $value = $this->toConfigValue($pconfig['v']);
                        if (isset($value)) {
                                $return[$pconfig['cat']][$pconfig['k']] = $value;
                        }
@@ -76,8 +76,7 @@ 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)) {
                                return $value;
@@ -102,13 +101,13 @@ class PreloadPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfig
                // 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;
+               $dbvalue = $this->toDbValue($value);
 
                return DBA::update('pconfig', ['v' => $dbvalue], ['uid' => $uid, 'cat' => $cat, 'k' => $key], true);
        }