aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Lib/Config.php
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2023-12-27 15:05:09 +0100
committerHarald Eilertsen <haraldei@anduin.net>2023-12-27 15:05:09 +0100
commitf5a028fccf6a738c3b5722f0db661d0333f3faff (patch)
treee9c93a7b432d2d2cdec081431290e8d20a97571b /Zotlabs/Lib/Config.php
parent7cb8ecd36b128d07b5086904af48601b9096cdea (diff)
parentc3a235242eb180860ac778743184d2297dd8f3a9 (diff)
downloadvolse-hubzilla-f5a028fccf6a738c3b5722f0db661d0333f3faff.tar.gz
volse-hubzilla-f5a028fccf6a738c3b5722f0db661d0333f3faff.tar.bz2
volse-hubzilla-f5a028fccf6a738c3b5722f0db661d0333f3faff.zip
Merge branch 'dev' into tests/test-db-setup-wip
Diffstat (limited to 'Zotlabs/Lib/Config.php')
-rw-r--r--Zotlabs/Lib/Config.php26
1 files changed, 18 insertions, 8 deletions
diff --git a/Zotlabs/Lib/Config.php b/Zotlabs/Lib/Config.php
index 40d5cc246..5e735be34 100644
--- a/Zotlabs/Lib/Config.php
+++ b/Zotlabs/Lib/Config.php
@@ -36,7 +36,7 @@ class Config {
if (! array_key_exists('config_loaded', App::$config[$family])) {
$r = q("SELECT * FROM config WHERE cat = '%s'", dbesc($family));
- if ($r === false) {
+ if ($r === false && !App::$install) {
sleep(3);
$recursionCounter ++;
if ($recursionCounter > 10) {
@@ -44,7 +44,7 @@ class Config {
}
self::Load($family, $recursionCounter);
}
- else {
+ elseif (is_array($r)) {
foreach ($r as $rr) {
$k = $rr['k'];
App::$config[$family][$k] = $rr['v'];
@@ -72,7 +72,7 @@ class Config {
*/
public static function Set($family, $key, $value) {
// manage array value
- $dbvalue = ((is_array($value)) ? serialise($value) : $value);
+ $dbvalue = ((is_array($value)) ? 'json:' . json_encode($value) : $value);
$dbvalue = ((is_bool($dbvalue)) ? intval($dbvalue) : $dbvalue);
if (self::Get($family, $key) === false || (! self::get_from_storage($family, $key))) {
@@ -121,6 +121,7 @@ class Config {
* @return mixed Return value or false on error or if not set
*/
public static function Get($family, $key, $default = false) {
+
if ((! array_key_exists($family, App::$config)) || (! array_key_exists('config_loaded', App::$config[$family]))) {
self::Load($family);
}
@@ -130,11 +131,20 @@ class Config {
return $default;
}
- return ((! is_array(App::$config[$family][$key])) && (preg_match('|^a:[0-9]+:{.*}$|s', App::$config[$family][$key]))
- ? unserialize(App::$config[$family][$key])
- : App::$config[$family][$key]
- );
-
+ $value = App::$config[$family][$key];
+
+ if (! is_array($value)) {
+ if (substr($value, 0, 5) == 'json:') {
+ return json_decode(substr($value, 5), true);
+ } else if (preg_match('|^a:[0-9]+:{.*}$|s', $value)) {
+ // Unserialize in inherently unsafe. Try to mitigate by not
+ // allowing unserializing objects. Only kept for backwards
+ // compatibility. JSON serialization should be prefered.
+ return unserialize($value, array('allowed_classes' => false));
+ } else {
+ return $value;
+ }
+ }
}
return $default;