Skip to content

Commit

Permalink
[REF] start unravelling the way we retrieve the saved search
Browse files Browse the repository at this point in the history
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
  • Loading branch information
eileenmcnaughton committed Jul 26, 2021
1 parent 4ca50ef commit 2f59eeb
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions CRM/Contact/BAO/GroupContactCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,10 @@ private static function updateCacheFromTempTable(CRM_Utils_SQL_TempTable $groupC
*/
protected static function insertGroupContactsIntoTempTable(string $tempTableName, int $groupID, ?int $savedSearchID, ?string $children): void {
if ($savedSearchID) {
$ssParams = CRM_Contact_BAO_SavedSearch::getSearchParams($savedSearchID);
$savedSearch = \Civi\Api4\SavedSearch::get(FALSE)
->addWhere('id', '=', $savedSearchID)
->execute()
->first();

$excludeClause = "NOT IN (
SELECT contact_id FROM civicrm_group_contact
Expand All @@ -805,9 +808,21 @@ protected static function insertGroupContactsIntoTempTable(string $tempTableName
$addSelect = "$groupID AS group_id";

if (!empty($ssParams['api_entity'])) {
$sql = self::getApiSQL($ssParams, $addSelect, $excludeClause);
$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);
Expand Down

0 comments on commit 2f59eeb

Please sign in to comment.