mirror of
https://github.com/friendica/friendica
synced 2025-04-27 13:10:10 +00:00
Fix multiple serialized values
This commit is contained in:
parent
7560939d75
commit
d772331b91
4 changed files with 71 additions and 6 deletions
|
@ -61,15 +61,13 @@ class DatabaseConfig implements IManageConfigValues
|
|||
|
||||
foreach ($setCache->getAll() as $category => $data) {
|
||||
foreach ($data as $key => $value) {
|
||||
$this->cache->set($category, $key, $value, Cache::SOURCE_DATA);
|
||||
$this->database->insert('config', ['cat' => $category, 'k' => $key, 'v' => serialize($value)], Database::INSERT_UPDATE);
|
||||
$this->set($category, $key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($delCache->getAll() as $category => $keys) {
|
||||
foreach ($keys as $key => $value) {
|
||||
$this->cache->delete($category, $key);
|
||||
$this->database->delete('config', ['cat' => $category, 'k' => $key]);
|
||||
$this->delete($category, $key);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,6 +83,10 @@ class DatabaseConfig implements IManageConfigValues
|
|||
/** {@inheritDoc} */
|
||||
public function set(string $cat, string $key, $value): bool
|
||||
{
|
||||
// In case someone or something already serialized a config entry, unserialize it first
|
||||
// We serialize values just once
|
||||
$value = SerializeUtil::maybeUnserialize($value);
|
||||
|
||||
$this->cache->set($cat, $key, $value, Cache::SOURCE_DATA);
|
||||
return $this->database->insert('config', ['cat' => $cat, 'k' => $key, 'v' => serialize($value)], Database::INSERT_UPDATE);
|
||||
}
|
||||
|
|
|
@ -28,10 +28,24 @@ namespace Friendica\Core\Config\Util;
|
|||
*/
|
||||
class SerializeUtil
|
||||
{
|
||||
/**
|
||||
* Checks if the value needs to get unserialized and returns the unserialized value
|
||||
*
|
||||
* @param mixed $value A possible serialized value
|
||||
*
|
||||
* @return mixed The unserialized value
|
||||
*/
|
||||
public static function maybeUnserialize($value)
|
||||
{
|
||||
if (static::isSerialized($value)) {
|
||||
return @unserialize(trim($value));
|
||||
// This checks for possible multiple serialized values
|
||||
while (SerializeUtil::isSerialized($value)) {
|
||||
$oldValue = $value;
|
||||
$value = @unserialize($value);
|
||||
|
||||
// If there's no change after the unserialize call, break the loop (avoid endless loops)
|
||||
if ($oldValue === $value) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue