Skip to content

Commit d96f798

Browse files
[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
1 parent 4ca50ef commit d96f798

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

CRM/Contact/BAO/GroupContactCache.php

+19-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Civi\Api4\Group;
1414
use Civi\Api4\Query\Api4SelectQuery;
1515
use Civi\Api4\Query\SqlExpression;
16+
use Civi\Api4\SavedSearch;
1617

1718
/**
1819
*
@@ -796,18 +797,33 @@ private static function updateCacheFromTempTable(CRM_Utils_SQL_TempTable $groupC
796797
*/
797798
protected static function insertGroupContactsIntoTempTable(string $tempTableName, int $groupID, ?int $savedSearchID, ?string $children): void {
798799
if ($savedSearchID) {
799-
$ssParams = CRM_Contact_BAO_SavedSearch::getSearchParams($savedSearchID);
800+
$savedSearch = SavedSearch::get(FALSE)
801+
->addWhere('id', '=', $savedSearchID)
802+
->execute()
803+
->first();
800804

801805
$excludeClause = "NOT IN (
802806
SELECT contact_id FROM civicrm_group_contact
803807
WHERE civicrm_group_contact.status = 'Removed'
804808
AND civicrm_group_contact.group_id = $groupID )";
805809
$addSelect = "$groupID AS group_id";
806810

807-
if (!empty($ssParams['api_entity'])) {
808-
$sql = self::getApiSQL($ssParams, $addSelect, $excludeClause);
811+
if (!empty($savedSearch['api_entity'])) {
812+
$sql = self::getApiSQL($savedSearch, $addSelect, $excludeClause);
809813
}
810814
else {
815+
$fv = CRM_Contact_BAO_SavedSearch::getFormValues($savedSearchID);
816+
//check if the saved search has mapping id
817+
if ($savedSearch['mapping_id']) {
818+
$ssParams = CRM_Core_BAO_Mapping::formattedFields($fv);
819+
}
820+
elseif (!empty($fv['customSearchID'])) {
821+
$ssParams = $fv;
822+
}
823+
else {
824+
$ssParams = CRM_Contact_BAO_Query::convertFormValues($fv);
825+
}
826+
811827
// CRM-7021 rectify params to what proximity search expects if there is a value for prox_distance
812828
if (!empty($ssParams)) {
813829
CRM_Contact_BAO_ProximityQuery::fixInputParams($ssParams);

0 commit comments

Comments
 (0)