]> git.mxchange.org Git - friendica.git/commitdiff
Use toConfigValue in case of serialized, legacy data
authorPhilipp <admin@philipp.info>
Wed, 28 Dec 2022 02:32:52 +0000 (03:32 +0100)
committerPhilipp <admin@philipp.info>
Tue, 3 Jan 2023 13:22:05 +0000 (14:22 +0100)
src/Core/Config/ValueObject/Cache.php

index c427996c35bcf7c94618c8ddfcace4d6bcf20691..2bac625ad2a8d9b87da6cbe5283aa8b7276948ec 100644 (file)
@@ -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.
         *