*/
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
{
parent::__construct();
+ $this->config_loaded = [];
+
if (isset($uid)) {
$this->load($uid, 'config');
}
{
$return = [];
- if ($this->config_loaded) {
+ if (empty($uid)) {
return $return;
}
- if (empty($uid)) {
+ 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);
- $this->config_loaded = true;
+ $this->config_loaded[$uid] = true;
return $return;
}
public function get($uid, $cat, $key)
{
if (!$this->isConnected()) {
- return '!<unset>!';
+ return null;
}
- if (!$this->config_loaded) {
+ if (!$this->isLoaded($uid, $cat, $key)) {
$this->load($uid, $cat);
}
$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;
}
/**
return false;
}
- if (!$this->config_loaded) {
+ 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);
}
/**
return false;
}
- if (!$this->config_loaded) {
+ if (!$this->isLoaded($uid, $cat, $key)) {
$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]);
}
/**
return false;
}
- return $this->config_loaded;
+ return isset($this->config_loaded[$uid]) && $this->config_loaded[$uid];
}
}