From 88b3effc180c5477bc8002b9d9ea8f3f628588dd Mon Sep 17 00:00:00 2001 From: Philipp Date: Wed, 28 Dec 2022 03:32:52 +0100 Subject: [PATCH] Use toConfigValue in case of serialized, legacy data --- src/Core/Config/ValueObject/Cache.php | 31 +++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/Core/Config/ValueObject/Cache.php b/src/Core/Config/ValueObject/Cache.php index c427996c35..2bac625ad2 100644 --- a/src/Core/Config/ValueObject/Cache.php +++ b/src/Core/Config/ValueObject/Cache.php @@ -182,6 +182,8 @@ class Cache $key == 'password' && is_string($value)) { $this->config[$cat][$key] = new HiddenString((string)$value); + } else if (is_string($value)) { + $this->config[$cat][$key] = self::toConfigValue($value); } else { $this->config[$cat][$key] = $value; } @@ -191,6 +193,35 @@ class Cache 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. *