From e99e9a300367bbe11ef99b04babd1c33636e53de Mon Sep 17 00:00:00 2001 From: mainframe98 Date: Tue, 24 Dec 2024 16:23:25 +0100 Subject: [PATCH] PhabricatorLiskDAO: Fragment serializer cache by class Summary: This restores the pre-PHP 8.1 behavior, where values of static variables within inherited methods were independent of each other. With PHP 8.1, this was changed to be truly 'static', which causes problems when one derivate of PhabricatorLiskDAO defines a custom serializer but another does not. This came to light in T15726, but only for the Fund application, which is a prototype, and deprecated. This fixes Fund, but more importantly, everything else that would be broken by this, whatever it was. Ref: https://wiki.php.net/rfc/static_variable_inheritance Previous stacktrace: ``` EXCEPTION: (RuntimeException) Undefined array key "totalAsCurrency" at [/src/error/PhutilErrorHandler.php:273] #0 <#2> PhutilErrorHandler::handleError(integer, string, string, integer) called at [/src/infrastructure/storage/lisk/PhabricatorLiskDAO.php:345] #1 <#2> PhabricatorLiskDAO::willWriteData(array) called at [/src/infrastructure/storage/lisk/LiskDAO.php:1085] #2 <#2> LiskDAO::insertRecordIntoDatabase(string) called at [/src/infrastructure/storage/lisk/LiskDAO.php:958] #3 <#2> LiskDAO::insert() called at [/src/infrastructure/storage/lisk/LiskDAO.php:927] #4 <#2> LiskDAO::save() called at [/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php:1405] [...] ``` Test Plan: On PHP 8.1+: 1. Visit http://phorge.localhost/applications/ and enable the deprecated prototype applications "Fund" and "Phortune" via "Configure" 2. Visit http://phorge.localhost/phortune/merchant/edit/ and create a merchant 3. Visit http://phorge.localhost/fund/create/ and click the "Create New Initiative" button Reviewers: O1 Blessed Committers, aklapper, valerio.bozzolan Reviewed By: O1 Blessed Committers, aklapper, valerio.bozzolan Subscribers: aklapper, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15064 Differential Revision: https://we.phorge.it/D25859 --- .../storage/lisk/PhabricatorLiskDAO.php | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/infrastructure/storage/lisk/PhabricatorLiskDAO.php b/src/infrastructure/storage/lisk/PhabricatorLiskDAO.php index 32cd10da23..e2714bce03 100644 --- a/src/infrastructure/storage/lisk/PhabricatorLiskDAO.php +++ b/src/infrastructure/storage/lisk/PhabricatorLiskDAO.php @@ -322,26 +322,28 @@ abstract class PhabricatorLiskDAO extends LiskDAO { protected function willReadData(array &$data) { parent::willReadData($data); - static $custom; - if ($custom === null) { - $custom = $this->getConfigOption(self::CONFIG_APPLICATION_SERIALIZERS); + static $custom = array(); + if (!isset($custom[static::class])) { + $custom[static::class] = $this->getConfigOption( + self::CONFIG_APPLICATION_SERIALIZERS); } - if ($custom) { - foreach ($custom as $key => $serializer) { + if (!empty($custom[static::class])) { + foreach ($custom[static::class] as $key => $serializer) { $data[$key] = $serializer->willReadValue($data[$key]); } } } protected function willWriteData(array &$data) { - static $custom; - if ($custom === null) { - $custom = $this->getConfigOption(self::CONFIG_APPLICATION_SERIALIZERS); + static $custom = array(); + if (!isset($custom[static::class])) { + $custom[static::class] = $this->getConfigOption( + self::CONFIG_APPLICATION_SERIALIZERS); } - if ($custom) { - foreach ($custom as $key => $serializer) { + if (!empty($custom[static::class])) { + foreach ($custom[static::class] as $key => $serializer) { $data[$key] = $serializer->willWriteValue($data[$key]); } }