From e10613e2393ad2e03334d49dbc69cdba0e806195 Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Sat, 3 Feb 2024 13:16:59 +0100 Subject: [PATCH] Replace serialize usages refs #1744 --- lib/GalettePaypal/PaypalHistory.php | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/lib/GalettePaypal/PaypalHistory.php b/lib/GalettePaypal/PaypalHistory.php index 4fd0549..4e25929 100644 --- a/lib/GalettePaypal/PaypalHistory.php +++ b/lib/GalettePaypal/PaypalHistory.php @@ -23,6 +23,7 @@ use Analog\Analog; use Galette\Core\Db; +use Galette\Core\Galette; use Galette\Core\Login; use Galette\Core\History; use Galette\Core\Preferences; @@ -79,7 +80,7 @@ public function add(array|string $action, string $argument = '', string $query = 'history_date' => date('Y-m-d H:i:s'), 'amount' => $request['mc_gross'], 'comments' => $request['item_name'], - 'request' => serialize($request), + 'request' => Galette::jsonEncode($request), 'signature' => $request['verify_sign'], 'state' => self::STATE_NONE ); @@ -143,24 +144,11 @@ public function getPaypalHistory(): array if (count($orig) > 0) { foreach ($orig as $o) { try { - $oa = unserialize($o['request']); - } catch (\ErrorException $err) { - Analog::log( - 'Error loading Paypal history entry #' . $o[$this->getPk()] . - ' ' . $err->getMessage(), - Analog::WARNING - ); - - //maybe an unserialization issue, try to fix - $data = preg_replace_callback( - '!s:(\d+):"(.*?)";!', - function ($match) { - return ($match[1] == strlen($match[2])) ? - $match[0] : 's:' . strlen($match[2]) . ':"' . $match[2] . '";'; - }, - $o['request'] - ); - $oa = unserialize($data); + if (Galette::isSerialized($o['request'])) { + $oa = unserialize($o['request']); + } else { + $oa = Galette::jsonDecode($o['request']); + } } catch (\Exception $e) { Analog::log( 'Error loading Paypal history entry #' . $o[$this->getPk()] .