if (DBA::isResult($pconfigs)) {
while ($pconfig = DBA::fetch($pconfigs)) {
$key = $pconfig['k'];
+ $value = $this->toConfigValue($pconfig['v']);
- $return[$key] = $pconfig['v'];
-
+ // The value was in the db, so don't check it again (unless you have to)
$this->in_db[$uid][$cat][$key] = true;
+
+ if (isset($value)) {
+ $return[$key] = $value;
+ }
}
} else if ($cat != 'config') {
// Negative caching
- $return = "!<unset>!";
+ $return = null;
}
DBA::close($pconfigs);
/**
* {@inheritdoc}
+ *
+ * @param bool $mark if true, mark the selection of the current cat/key pair
*/
- public function get($uid, $cat, $key)
+ public function get($uid, $cat, $key, $mark = true)
{
if (!$this->isConnected()) {
- return '!<unset>!';
+ return null;
+ }
+
+ // The value was in the db, so don't check it again (unless you have to)
+ if ($mark) {
+ $this->in_db[$uid][$cat][$key] = true;
}
$pconfig = DBA::selectFirst('pconfig', ['v'], ['uid' => $uid, 'cat' => $cat, 'k' => $key]);
if (DBA::isResult($pconfig)) {
- // manage array value
- $value = (preg_match("|^a:[0-9]+:{.*}$|s", $pconfig['v']) ? unserialize($pconfig['v']) : $pconfig['v']);
-
- $this->in_db[$uid][$cat][$key] = true;
- return $value;
- } else {
+ $value = $this->toConfigValue($pconfig['v']);
- $this->in_db[$uid][$cat][$key] = false;
- return '!<unset>!';
+ if (isset($value)) {
+ return $value;
+ }
}
+
+ $this->in_db[$uid][$cat][$key] = false;
+ return null;
}
/**
// 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);
+ $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] = [];
$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);
return false;
}
- if (!empty($this->in_db[$uid][$cat][$key])) {
+ if (isset($this->in_db[$uid][$cat][$key])) {
unset($this->in_db[$uid][$cat][$key]);
}
- $result = DBA::delete('pconfig', ['uid' => $uid, 'cat' => $cat, 'k' => $key]);
-
- return $result;
+ return DBA::delete('pconfig', ['uid' => $uid, 'cat' => $cat, 'k' => $key]);
}
/**