From 2fc81898dabafafbdc902bfae96c3c64a1fc0700 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Mon, 18 Feb 2019 14:00:34 +0100 Subject: [PATCH 1/7] 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 5d06dc2b3..c0d680d2c 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 d3c38623b..4485ee5df 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 b1866a259..d4ce6406b 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 857f2b176..090d0f5c6 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 54da327db..4ebcc8748 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); + } + } } } } From 5157084969e5f29a4979d3d7a8b3641a13a33697 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Mon, 18 Feb 2019 14:10:04 +0100 Subject: [PATCH 2/7] negative set --- src/Core/Config/Adapter/PreloadConfigAdapter.php | 2 ++ src/Core/Config/Adapter/PreloadPConfigAdapter.php | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/Core/Config/Adapter/PreloadConfigAdapter.php b/src/Core/Config/Adapter/PreloadConfigAdapter.php index d4ce6406b..218648cbd 100644 --- a/src/Core/Config/Adapter/PreloadConfigAdapter.php +++ b/src/Core/Config/Adapter/PreloadConfigAdapter.php @@ -35,6 +35,8 @@ class PreloadConfigAdapter extends AbstractDbaConfigAdapter implements IConfigAd $value = $config['v']; if (isset($value) && $value !== '') { $return[$config['cat']][$config['k']] = $value; + } else { + $return[$config['cat']][$config['k']] = '!!'; } } DBA::close($configs); diff --git a/src/Core/Config/Adapter/PreloadPConfigAdapter.php b/src/Core/Config/Adapter/PreloadPConfigAdapter.php index 090d0f5c6..5c736b2ff 100644 --- a/src/Core/Config/Adapter/PreloadPConfigAdapter.php +++ b/src/Core/Config/Adapter/PreloadPConfigAdapter.php @@ -47,6 +47,8 @@ class PreloadPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfig $value = $pconfig['v']; if (isset($value) && $value !== '') { $return[$pconfig['cat']][$pconfig['k']] = $value; + } else { + $return[$pconfig['cat']][$pconfig['k']] = '!!'; } } DBA::close($pconfigs); From f825fa1d1ca78d3aed43be5a8fc84140eb0c2a9d Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Mon, 18 Feb 2019 14:21:13 +0100 Subject: [PATCH 3/7] tmp alert --- view/theme/frio/style.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/view/theme/frio/style.php b/view/theme/frio/style.php index d8bffa9c6..824378793 100644 --- a/view/theme/frio/style.php +++ b/view/theme/frio/style.php @@ -2,9 +2,9 @@ /** * @file view/theme/frio/style.php */ + use Friendica\Core\Config; use Friendica\Core\PConfig; -use Friendica\Model\Profile; require_once 'view/theme/frio/php/PHPColors/Color.php'; @@ -20,6 +20,7 @@ if ($a->module !== 'install') { // Load the profile owners pconfig. $scheme = PConfig::get($uid, 'frio', 'scheme', PConfig::get($uid, 'frio', 'schema')); + \Friendica\Core\Logger::alert($scheme); $nav_bg = PConfig::get($uid, 'frio', 'nav_bg'); $nav_icon_color = PConfig::get($uid, 'frio', 'nav_icon_color'); $link_color = PConfig::get($uid, 'frio', 'link_color'); From 1194e9b41ea21db22ffde4da8eff66fd4d507c6f Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Mon, 18 Feb 2019 14:34:30 +0100 Subject: [PATCH 4/7] set config_loaded with uid --- .../Config/Adapter/PreloadPConfigAdapter.php | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/Core/Config/Adapter/PreloadPConfigAdapter.php b/src/Core/Config/Adapter/PreloadPConfigAdapter.php index 5c736b2ff..72266744f 100644 --- a/src/Core/Config/Adapter/PreloadPConfigAdapter.php +++ b/src/Core/Config/Adapter/PreloadPConfigAdapter.php @@ -13,7 +13,10 @@ use Friendica\Database\DBA; */ class PreloadPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfigAdapter { - private $config_loaded = false; + /** + * @var array true if config for user is loaded + */ + private $config_loaded; /** * @param int $uid The UID of the current user @@ -25,6 +28,8 @@ class PreloadPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfig if (isset($uid)) { $this->load($uid, 'config'); } + + $this->config_loaded = []; } /** @@ -34,11 +39,11 @@ class PreloadPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfig { $return = []; - if ($this->config_loaded) { + if (empty($uid)) { return $return; } - if (empty($uid)) { + if ($this->isLoaded($uid, $cat, null)) { return $return; } @@ -53,7 +58,7 @@ class PreloadPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfig } DBA::close($pconfigs); - $this->config_loaded = true; + $this->config_loaded[$uid] = true; return $return; } @@ -67,7 +72,7 @@ class PreloadPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfig return '!!'; } - if (!$this->config_loaded) { + if (!$this->isLoaded($uid, $cat, $key)) { $this->load($uid, $cat); } @@ -92,7 +97,7 @@ class PreloadPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfig return false; } - if (!$this->config_loaded) { + if ($this->isLoaded($uid, $cat, $key)) { $this->load($uid, $cat); } // We store our setting values as strings. @@ -121,7 +126,7 @@ class PreloadPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfig return false; } - if (!$this->config_loaded) { + if (!$this->isLoaded($uid, $cat, $key)) { $this->load($uid, $cat); } @@ -139,6 +144,6 @@ class PreloadPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfig return false; } - return $this->config_loaded; + return isset($this->config_loaded[$uid]) && $this->config_loaded[$uid]; } } From 5127a113aa7fb1c99a4e50febdbade08da5ff4e4 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Mon, 18 Feb 2019 14:40:35 +0100 Subject: [PATCH 5/7] set config_loaded with uid --- src/Core/Config/Adapter/PreloadPConfigAdapter.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Core/Config/Adapter/PreloadPConfigAdapter.php b/src/Core/Config/Adapter/PreloadPConfigAdapter.php index 72266744f..bc49d623f 100644 --- a/src/Core/Config/Adapter/PreloadPConfigAdapter.php +++ b/src/Core/Config/Adapter/PreloadPConfigAdapter.php @@ -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,7 +43,7 @@ class PreloadPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfig return $return; } - if ($this->isLoaded($uid, $cat, null)) { + if (!$this->isLoaded($uid, $cat, null)) { return $return; } From c2176aad364f657094b6dc9a603a1e2d18a32ca9 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Mon, 18 Feb 2019 14:45:24 +0100 Subject: [PATCH 6/7] bugfix --- src/Core/Config/Adapter/PreloadPConfigAdapter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/Config/Adapter/PreloadPConfigAdapter.php b/src/Core/Config/Adapter/PreloadPConfigAdapter.php index bc49d623f..12e25df9f 100644 --- a/src/Core/Config/Adapter/PreloadPConfigAdapter.php +++ b/src/Core/Config/Adapter/PreloadPConfigAdapter.php @@ -97,7 +97,7 @@ 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. From 6c22f70b62d0a3ffae12371f3d3464bd5da4cc8d Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Mon, 18 Feb 2019 14:48:26 +0100 Subject: [PATCH 7/7] revert style.php changes --- view/theme/frio/style.php | 1 - 1 file changed, 1 deletion(-) diff --git a/view/theme/frio/style.php b/view/theme/frio/style.php index 824378793..5fada9dd4 100644 --- a/view/theme/frio/style.php +++ b/view/theme/frio/style.php @@ -20,7 +20,6 @@ if ($a->module !== 'install') { // Load the profile owners pconfig. $scheme = PConfig::get($uid, 'frio', 'scheme', PConfig::get($uid, 'frio', 'schema')); - \Friendica\Core\Logger::alert($scheme); $nav_bg = PConfig::get($uid, 'frio', 'nav_bg'); $nav_icon_color = PConfig::get($uid, 'frio', 'nav_icon_color'); $link_color = PConfig::get($uid, 'frio', 'link_color');