Use toConfigValue in case of serialized, legacy data

This commit is contained in:
Philipp Holzer 2022-12-28 03:32:52 +01:00
parent 10f3de0aa2
commit 88b3effc18
Signed by: nupplaPhil
GPG key ID: 24A7501396EB5432

View file

@ -182,6 +182,8 @@ class Cache
$key == 'password' && $key == 'password' &&
is_string($value)) { is_string($value)) {
$this->config[$cat][$key] = new HiddenString((string)$value); $this->config[$cat][$key] = new HiddenString((string)$value);
} else if (is_string($value)) {
$this->config[$cat][$key] = self::toConfigValue($value);
} else { } else {
$this->config[$cat][$key] = $value; $this->config[$cat][$key] = $value;
} }
@ -191,6 +193,35 @@ class Cache
return true; return true;
} }
/**
* Formats a DB value to a config value
* - null = The db-value isn't set
* - bool = The db-value is either '0' or '1'
* - array = The db-value is a serialized array
* - string = The db-value is a string
*
* Keep in mind that there aren't any numeric/integer config values in the database
*
* @param string|null $value
*
* @return null|array|string
*/
public static function toConfigValue(?string $value)
{
if (!isset($value)) {
return null;
}
switch (true) {
// manage array value
case preg_match("|^a:[0-9]+:{.*}$|s", $value):
return unserialize($value);
default:
return $value;
}
}
/** /**
* Deletes a value from the config cache. * Deletes a value from the config cache.
* *