From d96f7984ff41c1ba9ef8b7e061ac3d82405c8af5 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Mon, 26 Jul 2021 13:56:41 +1200 Subject: [PATCH] [REF] start unravelling the way we retrieve the saved search We have 3 types of saved searches - search kit - legacy core searches - legacy custom searches The only information these 3 need to load is the savedSearch details and the group ID (to add in the add & exclude). The wrangling of the params should happen in the getSql functions - which we can think about being in a listener once they have standard inputs & outputs. However, to get to that point we want to standardise those inputs & outputs. This removes only point of randomness - ie savedSearch has a consistent value & the wrangling of what is in it is pushed closer to the relevant functions --- CRM/Contact/BAO/GroupContactCache.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/CRM/Contact/BAO/GroupContactCache.php b/CRM/Contact/BAO/GroupContactCache.php index 740ba9b704..47cfbdcd2d 100644 --- a/CRM/Contact/BAO/GroupContactCache.php +++ b/CRM/Contact/BAO/GroupContactCache.php @@ -13,6 +13,7 @@ use Civi\API\Request; use Civi\Api4\Group; use Civi\Api4\Query\Api4SelectQuery; use Civi\Api4\Query\SqlExpression; +use Civi\Api4\SavedSearch; /** * @@ -796,7 +797,10 @@ ORDER BY gc.contact_id, g.children */ protected static function insertGroupContactsIntoTempTable(string $tempTableName, int $groupID, ?int $savedSearchID, ?string $children): void { if ($savedSearchID) { - $ssParams = CRM_Contact_BAO_SavedSearch::getSearchParams($savedSearchID); + $savedSearch = SavedSearch::get(FALSE) + ->addWhere('id', '=', $savedSearchID) + ->execute() + ->first(); $excludeClause = "NOT IN ( SELECT contact_id FROM civicrm_group_contact @@ -804,10 +808,22 @@ ORDER BY gc.contact_id, g.children AND civicrm_group_contact.group_id = $groupID )"; $addSelect = "$groupID AS group_id"; - if (!empty($ssParams['api_entity'])) { - $sql = self::getApiSQL($ssParams, $addSelect, $excludeClause); + if (!empty($savedSearch['api_entity'])) { + $sql = self::getApiSQL($savedSearch, $addSelect, $excludeClause); } else { + $fv = CRM_Contact_BAO_SavedSearch::getFormValues($savedSearchID); + //check if the saved search has mapping id + if ($savedSearch['mapping_id']) { + $ssParams = CRM_Core_BAO_Mapping::formattedFields($fv); + } + elseif (!empty($fv['customSearchID'])) { + $ssParams = $fv; + } + else { + $ssParams = CRM_Contact_BAO_Query::convertFormValues($fv); + } + // CRM-7021 rectify params to what proximity search expects if there is a value for prox_distance if (!empty($ssParams)) { CRM_Contact_BAO_ProximityQuery::fixInputParams($ssParams); -- 2.25.1