From 2fc81898dabafafbdc902bfae96c3c64a1fc0700 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Mon, 18 Feb 2019 14:00:34 +0100 Subject: [PATCH] Preload Adapter Fix --- src/Core/Config/Adapter/JITConfigAdapter.php | 9 +++++--- src/Core/Config/Adapter/JITPConfigAdapter.php | 8 ++++--- .../Config/Adapter/PreloadConfigAdapter.php | 5 +++- .../Config/Adapter/PreloadPConfigAdapter.php | 5 +++- src/Core/Config/Cache/ConfigCache.php | 23 ++++++++++++++----- 5 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/Core/Config/Adapter/JITConfigAdapter.php b/src/Core/Config/Adapter/JITConfigAdapter.php index 5d06dc2b3e..c0d680d2c9 100644 --- a/src/Core/Config/Adapter/JITConfigAdapter.php +++ b/src/Core/Config/Adapter/JITConfigAdapter.php @@ -33,10 +33,13 @@ class JITConfigAdapter extends AbstractDbaConfigAdapter implements IConfigAdapte $configs = DBA::select('config', ['v', 'k'], ['cat' => $cat]); while ($config = DBA::fetch($configs)) { - $key = $config['k']; + $key = $config['k']; + $value = $config['v']; - $return[$key] = $config['v']; - $this->in_db[$cat][$key] = true; + if (isset($value) && $value !== '') { + $return[$key] = $value; + $this->in_db[$cat][$key] = true; + } } DBA::close($configs); diff --git a/src/Core/Config/Adapter/JITPConfigAdapter.php b/src/Core/Config/Adapter/JITPConfigAdapter.php index d3c38623b4..4485ee5df9 100644 --- a/src/Core/Config/Adapter/JITPConfigAdapter.php +++ b/src/Core/Config/Adapter/JITPConfigAdapter.php @@ -29,10 +29,12 @@ class JITPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfigAdap if (DBA::isResult($pconfigs)) { while ($pconfig = DBA::fetch($pconfigs)) { $key = $pconfig['k']; + $value = $pconfig['v']; - $return[$key] = $pconfig['v']; - - $this->in_db[$uid][$cat][$key] = true; + if (isset($value) && $value !== '') { + $return[$key] = $value; + $this->in_db[$uid][$cat][$key] = true; + } } } else if ($cat != 'config') { // Negative caching diff --git a/src/Core/Config/Adapter/PreloadConfigAdapter.php b/src/Core/Config/Adapter/PreloadConfigAdapter.php index b1866a259d..d4ce6406b4 100644 --- a/src/Core/Config/Adapter/PreloadConfigAdapter.php +++ b/src/Core/Config/Adapter/PreloadConfigAdapter.php @@ -32,7 +32,10 @@ class PreloadConfigAdapter extends AbstractDbaConfigAdapter implements IConfigAd $configs = DBA::select('config', ['cat', 'v', 'k']); while ($config = DBA::fetch($configs)) { - $return[$config['cat']][$config['k']] = $config['v']; + $value = $config['v']; + if (isset($value) && $value !== '') { + $return[$config['cat']][$config['k']] = $value; + } } DBA::close($configs); diff --git a/src/Core/Config/Adapter/PreloadPConfigAdapter.php b/src/Core/Config/Adapter/PreloadPConfigAdapter.php index 857f2b1766..090d0f5c6f 100644 --- a/src/Core/Config/Adapter/PreloadPConfigAdapter.php +++ b/src/Core/Config/Adapter/PreloadPConfigAdapter.php @@ -44,7 +44,10 @@ class PreloadPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfig $pconfigs = DBA::select('pconfig', ['cat', 'v', 'k'], ['uid' => $uid]); while ($pconfig = DBA::fetch($pconfigs)) { - $return[$pconfig['cat']][$pconfig['k']] = $pconfig['v']; + $value = $pconfig['v']; + if (isset($value) && $value !== '') { + $return[$pconfig['cat']][$pconfig['k']] = $value; + } } DBA::close($pconfigs); diff --git a/src/Core/Config/Cache/ConfigCache.php b/src/Core/Config/Cache/ConfigCache.php index 54da327dba..4ebcc87482 100644 --- a/src/Core/Config/Cache/ConfigCache.php +++ b/src/Core/Config/Cache/ConfigCache.php @@ -36,11 +36,12 @@ class ConfigCache implements IConfigCache, IPConfigCache $keys = array_keys($config[$category]); foreach ($keys as $key) { - if (isset($config[$category][$key])) { + $value = $config[$category][$key]; + if (isset($value) && $value !== '!!') { if ($overwrite) { - $this->set($category, $key, $config[$category][$key]); + $this->set($category, $key, $value); } else { - $this->setDefault($category, $key, $config[$category][$key]); + $this->setDefault($category, $key, $value); } } } @@ -132,9 +133,19 @@ class ConfigCache implements IConfigCache, IPConfigCache */ public function loadP($uid, array $config) { - foreach ($config as $category => $values) { - foreach ($values as $key => $value) { - $this->setP($uid, $category, $key, $value); + $categories = array_keys($config); + + foreach ($categories as $category) { + if (isset($config[$category]) && is_array($config[$category])) { + + $keys = array_keys($config[$category]); + + foreach ($keys as $key) { + $value = $config[$category][$key]; + if (isset($value) && $value !== '!!') { + $this->setP($uid, $category, $key, $value); + } + } } } }