From e6bf2d49c2ca7519ce629313580d7b333936102d Mon Sep 17 00:00:00 2001 From: demeritcowboy Date: Wed, 22 Sep 2021 12:39:32 -0400 Subject: [PATCH] don't crash for nonexistent uf_id --- CRM/Core/BAO/UFMatch.php | 7 +++---- tests/phpunit/CRM/Core/BAO/UFMatchTest.php | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 tests/phpunit/CRM/Core/BAO/UFMatchTest.php diff --git a/CRM/Core/BAO/UFMatch.php b/CRM/Core/BAO/UFMatch.php index 9d0a58bbac..cc007958a1 100644 --- a/CRM/Core/BAO/UFMatch.php +++ b/CRM/Core/BAO/UFMatch.php @@ -624,13 +624,12 @@ AND domain_id = %4 return []; } - static $ufValues; - if ($ufID && !isset($ufValues[$ufID])) { + if (!isset(Civi::$statics[__CLASS__][__FUNCTION__][$ufID])) { $ufmatch = new CRM_Core_DAO_UFMatch(); $ufmatch->uf_id = $ufID; $ufmatch->domain_id = CRM_Core_Config::domainID(); if ($ufmatch->find(TRUE)) { - $ufValues[$ufID] = [ + Civi::$statics[__CLASS__][__FUNCTION__][$ufID] = [ 'uf_id' => $ufmatch->uf_id, 'uf_name' => $ufmatch->uf_name, 'contact_id' => $ufmatch->contact_id, @@ -638,7 +637,7 @@ AND domain_id = %4 ]; } } - return $ufValues[$ufID]; + return Civi::$statics[__CLASS__][__FUNCTION__][$ufID] ?? NULL; } /** diff --git a/tests/phpunit/CRM/Core/BAO/UFMatchTest.php b/tests/phpunit/CRM/Core/BAO/UFMatchTest.php new file mode 100644 index 0000000000..e9916b8ebc --- /dev/null +++ b/tests/phpunit/CRM/Core/BAO/UFMatchTest.php @@ -0,0 +1,18 @@ +assertNull($dontcrash); + } + +} -- 2.25.1