Prevent empty $uid from messing up the PreloadConfigAdapter

This commit is contained in:
Hypolite Petovan 2018-04-09 21:24:22 -04:00
parent 83c3744628
commit c7ad76f9ab

View File

@ -32,6 +32,10 @@ class PreloadPConfigAdapter extends BaseObject implements IPConfigAdapter
return; return;
} }
if (empty($uid)) {
return;
}
$pconfigs = dba::select('pconfig', ['cat', 'v', 'k'], ['uid' => $uid]); $pconfigs = dba::select('pconfig', ['cat', 'v', 'k'], ['uid' => $uid]);
while ($pconfig = dba::fetch($pconfigs)) { while ($pconfig = dba::fetch($pconfigs)) {
self::getApp()->setPConfigValue($uid, $pconfig['cat'], $pconfig['k'], $pconfig['v']); self::getApp()->setPConfigValue($uid, $pconfig['cat'], $pconfig['k'], $pconfig['v']);
@ -43,6 +47,10 @@ class PreloadPConfigAdapter extends BaseObject implements IPConfigAdapter
public function get($uid, $cat, $k, $default_value = null, $refresh = false) public function get($uid, $cat, $k, $default_value = null, $refresh = false)
{ {
if (!$this->config_loaded) {
$this->load($uid, $cat);
}
if ($refresh) { if ($refresh) {
$config = dba::selectFirst('pconfig', ['v'], ['uid' => $uid, 'cat' => $cat, 'k' => $k]); $config = dba::selectFirst('pconfig', ['v'], ['uid' => $uid, 'cat' => $cat, 'k' => $k]);
if (DBM::is_result($config)) { if (DBM::is_result($config)) {
@ -59,6 +67,9 @@ class PreloadPConfigAdapter extends BaseObject implements IPConfigAdapter
public function set($uid, $cat, $k, $value) public function set($uid, $cat, $k, $value)
{ {
if (!$this->config_loaded) {
$this->load($uid, $cat);
}
// We store our setting values as strings. // We store our setting values as strings.
// So we have to do the conversion here so that the compare below works. // So we have to do the conversion here so that the compare below works.
// The exception are array values. // The exception are array values.
@ -83,6 +94,10 @@ class PreloadPConfigAdapter extends BaseObject implements IPConfigAdapter
public function delete($uid, $cat, $k) public function delete($uid, $cat, $k)
{ {
if (!$this->config_loaded) {
$this->load($uid, $cat);
}
self::getApp()->deletePConfigValue($uid, $cat, $k); self::getApp()->deletePConfigValue($uid, $cat, $k);
$result = dba::delete('pconfig', ['uid' => $uid, 'cat' => $cat, 'k' => $k]); $result = dba::delete('pconfig', ['uid' => $uid, 'cat' => $cat, 'k' => $k]);