From 2c30573378ce598e9319e62b24765887061627a1 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Wed, 13 Oct 2021 22:45:29 -0400 Subject: [PATCH] APIv4 - Fix possible recursion during Entity::get() --- CRM/Contact/BAO/ContactType.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/CRM/Contact/BAO/ContactType.php b/CRM/Contact/BAO/ContactType.php index 790fe70b6a..fdf38a1816 100644 --- a/CRM/Contact/BAO/ContactType.php +++ b/CRM/Contact/BAO/ContactType.php @@ -68,14 +68,18 @@ class CRM_Contact_BAO_ContactType extends CRM_Contact_DAO_ContactType { */ public static function basicTypeInfo($includeInactive = FALSE) { $cacheKey = 'CRM_CT_BTI_' . (int) $includeInactive; - if (!Civi::cache('contactTypes')->has($cacheKey)) { - $contactType = ContactType::get(FALSE)->setSelect(['*'])->addWhere('parent_id', 'IS NULL'); + $contactTypes = Civi::cache('contactTypes')->get($cacheKey, []); + if (!$contactTypes) { + $query = CRM_Utils_SQL_Select::from('civicrm_contact_type') + ->where('parent_id IS NULL'); if ($includeInactive === FALSE) { - $contactType->addWhere('is_active', '=', 1); + $query->where('is_active = 1'); } - Civi::cache('contactTypes')->set($cacheKey, (array) $contactType->execute()->indexBy('name')); + $dao = CRM_Core_DAO::executeQuery($query->toSQL()); + $contactTypes = array_column($dao->fetchAll(), NULL, 'name'); + Civi::cache('contactTypes')->set($cacheKey, $contactTypes); } - return Civi::cache('contactTypes')->get($cacheKey); + return $contactTypes; } /** -- 2.25.1