$configs = DBA::select('config', ['v', 'k'], ['cat' => $cat]);
while ($config = DBA::fetch($configs)) {
- $key = $config['k'];
+ $key = $config['k'];
+ $value = $this->toConfigValue($config['v']);
- $return[$key] = $config['v'];
+ // The value was in the db, so don't check it again (unless you have to)
$this->in_db[$cat][$key] = true;
+
+ // just save it in case it is set
+ if (isset($value)) {
+ $return[$key] = $value;
+ }
}
DBA::close($configs);
- return [$cat => $config];
+ return [$cat => $return];
}
/**
* {@inheritdoc}
+ *
+ * @param bool $mark if true, mark the selection of the current cat/key pair
*/
- public function get($cat, $key)
+ public function get($cat, $key, $mark = true)
{
if (!$this->isConnected()) {
- return '!<unset>!';
+ return null;
+ }
+
+ // The value got checked, so mark it to avoid checking it over and over again
+ if ($mark) {
+ $this->in_db[$cat][$key] = true;
}
$config = DBA::selectFirst('config', ['v'], ['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']);
- $this->in_db[$cat][$key] = true;
- return $value;
- } else {
-
- $this->in_db[$cat][$key] = false;
- return '!<unset>!';
+ // just return it in case it is set
+ if (isset($value)) {
+ return $value;
+ }
}
+
+ 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($cat, $key);
+ $compare_value = (!is_array($value) ? (string)$value : $value);
+ $stored_value = $this->get($cat, $key, false);
if (!isset($this->in_db[$cat])) {
$this->in_db[$cat] = [];
$this->in_db[$cat][$key] = false;
}
- if (($stored === $dbvalue) && $this->in_db[$cat][$key]) {
+ if (isset($stored_value) && ($stored_value === $compare_value) && $this->in_db[$cat][$key]) {
return true;
}
- // manage array value
- $dbvalue = (is_array($value) ? serialize($value) : $dbvalue);
+ $dbvalue = $this->toDbValue($value);
$result = DBA::update('config', ['v' => $dbvalue], ['cat' => $cat, 'k' => $key], true);