3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
14 use Civi\Api4\Query\Api4SelectQuery
;
15 use Civi\Api4\Query\SqlExpression
;
20 * @copyright CiviCRM LLC https://civicrm.org/licensing
22 class CRM_Contact_BAO_GroupContactCache
extends CRM_Contact_DAO_GroupContactCache
{
25 * Get a list of caching modes.
29 public static function getModes(): array {
31 // Flush expired caches in response to user actions.
32 'opportunistic' => ts('Opportunistic Flush'),
33 // Flush expired caches via background cron jobs.
34 'deterministic' => ts('Cron Flush'),
39 * Check to see if we have cache entries for this group.
41 * If not, regenerate, else return.
43 * @param array $groupIDs
44 * Of group that we are checking against.
47 * TRUE if we did not regenerate, FALSE if we did
49 public static function check($groupIDs): bool {
50 if (empty($groupIDs)) {
54 return self
::loadAll($groupIDs);
58 * Formulate the query to see which groups needs to be refreshed.
60 * The calculation is based on their cache date and the smartGroupCacheTimeOut
62 * @param string $groupIDClause
63 * The clause which limits which groups we need to evaluate.
64 * @param bool $includeHiddenGroups
65 * Hidden groups are excluded by default.
68 * the sql query which lists the groups that need to be refreshed
70 public static function groupRefreshedClause($groupIDClause = NULL, $includeHiddenGroups = FALSE): string {
71 $smartGroupCacheTimeoutDateTime = self
::getCacheInvalidDateTime();
76 WHERE ( g.saved_search_id IS NOT NULL OR g.children IS NOT NULL )
80 OR cache_date <= $smartGroupCacheTimeoutDateTime
83 if (!$includeHiddenGroups) {
84 $query .= "AND (g.is_hidden = 0 OR g.is_hidden IS NULL)";
87 if (!empty($groupIDClause)) {
88 $query .= " AND ( $groupIDClause ) ";
95 * Check to see if a group has been refreshed recently.
97 * This is primarily used in a locking scenario when some other process might have refreshed things underneath
100 * @param int $groupID
102 * @param bool $includeHiddenGroups
103 * Hidden groups are excluded by default.
106 * the sql query which lists the groups that need to be refreshed
108 public static function shouldGroupBeRefreshed($groupID, $includeHiddenGroups = FALSE) {
109 $query = self
::groupRefreshedClause("g.id = %1", $includeHiddenGroups);
110 $params = [1 => [$groupID, 'Integer']];
112 // if the query returns the group ID, it means the group is a valid candidate for refreshing
113 return CRM_Core_DAO
::singleValueQuery($query, $params);
117 * Check to see if we have cache entries for this group.
119 * if not, regenerate, else return
121 * @param array|null $groupIDs groupIDs of group that we are checking against
122 * if empty, all groups are checked
124 * Limits the number of groups we evaluate.
127 * TRUE if we did not regenerate, FALSE if we did
129 public static function loadAll($groupIDs = NULL, $limit = 0) {
131 // Passing a single value is deprecated.
132 $groupIDs = (array) $groupIDs;
135 $processGroupIDs = self
::getGroupsNeedingRefreshing($groupIDs, $limit);
137 if (!empty($processGroupIDs)) {
138 self
::add($processGroupIDs);
144 * Build the smart group cache for given groups.
146 * @param array $groupIDs
148 public static function add($groupIDs) {
149 $groupIDs = (array) $groupIDs;
151 foreach ($groupIDs as $groupID) {
152 // first delete the current cache
153 $params = [['group', 'IN', [$groupID], 0, 0]];
154 // the below call updates the cache table as a byproduct of the query
155 CRM_Contact_BAO_Query
::apiQuery($params, ['contact_id'], NULL, NULL, 0, 0, FALSE);
160 * Store values into the group contact cache.
162 * @todo review use of INSERT IGNORE. This function appears to be slower that inserting
163 * with a left join. Also, 200 at once seems too little.
165 * @param array $groupID
166 * @param array $values
168 public static function store($groupID, &$values) {
171 // sort the values so we put group IDs in front and hence optimize
172 // mysql storage (or so we think) CRM-9493
175 // to avoid long strings, lets do BULK_INSERT_COUNT values at a time
176 while (!empty($values)) {
178 $input = array_splice($values, 0, CRM_Core_DAO
::BULK_INSERT_COUNT
);
179 $str = implode(',', $input);
180 $sql = "INSERT IGNORE INTO civicrm_group_contact_cache (group_id,contact_id) VALUES $str;";
181 CRM_Core_DAO
::executeQuery($sql);
183 self
::updateCacheTime($groupID, $processed);
187 * Change the cache_date.
189 * @param array $groupID
190 * @param bool $processed
191 * Whether the cache data was recently modified.
193 public static function updateCacheTime($groupID, $processed) {
194 // only update cache entry if we had any values
196 // also update the group with cache date information
197 $now = date('YmdHis');
203 $groupIDs = implode(',', $groupID);
206 SET cache_date = $now
207 WHERE id IN ( $groupIDs )
209 CRM_Core_DAO
::executeQuery($sql);
213 * Function to clear group contact cache and reset the corresponding
214 * group's cache and refresh date
216 * @param int $groupID
219 public static function clearGroupContactCache($groupID): void
{
220 $transaction = new CRM_Core_Transaction();
223 FROM civicrm_group_contact_cache g
224 WHERE g.group_id = %1 ";
227 UPDATE civicrm_group g
228 SET cache_date = null
232 1 => [$groupID, 'Integer'],
235 CRM_Core_DAO
::executeQuery($query, $params);
236 // also update the cache_date for these groups
237 CRM_Core_DAO
::executeQuery($update, $params);
239 $transaction->commit();
243 * Refresh the smart group cache tables.
245 * This involves clearing out any aged entries (based on the site timeout setting) and resetting the time outs.
247 * This function should be called via the opportunistic or deterministic cache refresh function to make the intent
250 protected static function flushCaches() {
252 $lock = self
::getLockForRefresh();
254 catch (CRM_Core_Exception
$e) {
255 // Someone else is kindly doing the refresh for us right now.
258 $params = [1 => [self
::getCacheInvalidDateTime(), 'String']];
259 $groupsDAO = CRM_Core_DAO
::executeQuery("SELECT id FROM civicrm_group WHERE cache_date <= %1", $params);
261 while ($groupsDAO->fetch()) {
262 $expiredGroups[] = $groupsDAO->id
;
264 if (!empty($expiredGroups)) {
265 $expiredGroups = implode(',', $expiredGroups);
266 CRM_Core_DAO
::executeQuery("DELETE FROM civicrm_group_contact_cache WHERE group_id IN ({$expiredGroups})");
268 // Clear these out without resetting them because we are not building caches here, only clearing them,
269 // so the state is 'as if they had never been built'.
270 CRM_Core_DAO
::executeQuery("UPDATE civicrm_group SET cache_date = NULL WHERE id IN ({$expiredGroups})");
276 * Check if the refresh is already initiated.
278 * We have 2 imperfect methods for this:
279 * 1) a static variable in the function. This works fine within a request
280 * 2) a mysql lock. This works fine as long as CiviMail is not running, or if mysql is version 5.7+
282 * Where these 2 locks fail we get 2 processes running at the same time, but we have at least minimised that.
284 * @return \Civi\Core\Lock\LockInterface
285 * @throws \CRM_Core_Exception
287 protected static function getLockForRefresh() {
288 if (!isset(Civi
::$statics[__CLASS__
]['is_refresh_init'])) {
289 Civi
::$statics[__CLASS__
] = ['is_refresh_init' => FALSE];
292 if (Civi
::$statics[__CLASS__
]['is_refresh_init']) {
293 throw new CRM_Core_Exception('A refresh has already run in this process');
295 $lock = Civi
::lockManager()->acquire('data.core.group.refresh');
296 if ($lock->isAcquired()) {
297 Civi
::$statics[__CLASS__
]['is_refresh_init'] = TRUE;
300 throw new CRM_Core_Exception('Mysql lock unavailable');
304 * Do an opportunistic cache refresh if the site is configured for these.
306 * Sites that do not run the smart group clearing cron job should refresh the
307 * caches on demand. The user session will be forced to wait so it is less
310 public static function opportunisticCacheFlush(): void
{
311 if (Civi
::settings()->get('smart_group_cache_refresh_mode') === 'opportunistic') {
317 * Do a forced cache refresh.
319 * This function is appropriate to be called by system jobs & non-user sessions.
321 public static function deterministicCacheFlush() {
322 if (self
::smartGroupCacheTimeout() == 0) {
323 CRM_Core_DAO
::executeQuery("TRUNCATE civicrm_group_contact_cache");
324 CRM_Core_DAO
::executeQuery("UPDATE civicrm_group SET cache_date = NULL");
332 * Remove one or more contacts from the smart group cache.
334 * @param int|array $cid
335 * @param null $groupId
338 * TRUE if successful.
339 * @throws \CRM_Core_Exception
341 public static function removeContact($cid, $groupId = NULL) {
344 foreach ((array) $cid as $c) {
345 $cids[] = CRM_Utils_Type
::escape($c, 'Integer');
348 $condition = count($cids) == 1 ?
"= {$cids[0]}" : "IN (" . implode(',', $cids) . ")";
350 $condition .= " AND group_id = " . CRM_Utils_Type
::escape($groupId, 'Integer');
352 $sql = "DELETE FROM civicrm_group_contact_cache WHERE contact_id $condition";
353 CRM_Core_DAO
::executeQuery($sql);
360 * Load the smart group cache for a saved search.
362 * @param object $group
363 * The smart group that needs to be loaded.
365 * deprecated parameter = Should we force a search through.
367 * @throws \API_Exception
368 * @throws \CRM_Core_Exception
369 * @throws \CiviCRM_API3_Exception
371 public static function load($group, $force = FALSE) {
372 $groupID = (int) $group->id
;
374 CRM_Core_Error
::deprecatedWarning('use invalidate group contact cache first.');
375 self
::invalidateGroupContactCache($group->id
);
378 // FIXME: some other process could have actually done the work before we got here,
379 // Ensure that work needs to be done before continuing
380 if (!self
::shouldGroupBeRefreshed($groupID, TRUE)) {
384 // grab a lock so other processes don't compete and do the same query
385 $lock = Civi
::lockManager()->acquire("data.core.group.{$groupID}");
386 if (!$lock->isAcquired()) {
387 // this can cause inconsistent results since we don't know if the other process
388 // will fill up the cache before our calling routine needs it.
389 // however this routine does not return the status either, so basically
390 // its a "lets return and hope for the best"
394 $groupContactsTempTable = CRM_Utils_SQL_TempTable
::build()
395 ->setCategory('gccache')
397 self
::buildGroupContactTempTable([$groupID], $groupContactsTempTable);
398 $tempTable = $groupContactsTempTable->getName();
400 // Don't call clearGroupContactCache as we don't want to clear the cache dates
401 // The will get updated by updateCacheTime() below and not clearing the dates reduces
402 // the chance that loadAll() will try and rebuild at the same time.
405 FROM civicrm_group_contact_cache g
406 WHERE g.group_id = %1 ";
408 1 => [$groupID, 'Integer'],
410 CRM_Core_DAO
::executeQuery($clearCacheQuery, $params);
412 CRM_Core_DAO
::executeQuery(
413 "INSERT IGNORE INTO civicrm_group_contact_cache (contact_id, group_id)
414 SELECT DISTINCT contact_id, group_id FROM $tempTable
416 $groupContactsTempTable->drop();
417 self
::updateCacheTime([$groupID], TRUE);
423 * Retrieve the smart group cache timeout in minutes.
425 * This checks if a timeout has been configured. If one has then smart groups should not
426 * be refreshed more frequently than the time out. If a group was recently refreshed it should not
427 * refresh again within that period.
431 public static function smartGroupCacheTimeout() {
432 $config = CRM_Core_Config
::singleton();
435 isset($config->smartGroupCacheTimeout
) &&
436 is_numeric($config->smartGroupCacheTimeout
)
438 return $config->smartGroupCacheTimeout
;
441 // Default to 5 minutes.
446 * Get all the smart groups that this contact belongs to.
448 * Note that this could potentially be a super slow function since
449 * it ensure that all contact groups are loaded in the cache
451 * @param int $contactID
454 * an array of groups that this contact belongs to
456 public static function contactGroup(int $contactID): array {
461 SELECT gc.group_id, gc.contact_id, g.title, g.children, g.description
462 FROM civicrm_group_contact_cache gc
463 INNER JOIN civicrm_group g ON g.id = gc.group_id
464 WHERE gc.contact_id = $contactID
465 AND (g.is_hidden = 0 OR g.is_hidden IS NULL)
466 ORDER BY gc.contact_id, g.children
469 $dao = CRM_Core_DAO
::executeQuery($sql);
471 $prevContactID = NULL;
472 while ($dao->fetch()) {
475 $prevContactID != $dao->contact_id
477 $contactGroup[$prevContactID]['groupTitle'] = implode(', ', $contactGroup[$prevContactID]['groupTitle']);
479 $prevContactID = $dao->contact_id
;
480 if (!array_key_exists($dao->contact_id
, $contactGroup)) {
481 $contactGroup[$dao->contact_id
]
482 = ['group' => [], 'groupTitle' => []];
485 $contactGroup[$dao->contact_id
]['group'][]
487 'id' => $dao->group_id
,
488 'title' => $dao->title
,
489 'description' => $dao->description
,
490 'children' => $dao->children
,
492 $contactGroup[$dao->contact_id
]['groupTitle'][] = $dao->title
;
495 if ($prevContactID) {
496 $contactGroup[$prevContactID]['groupTitle'] = implode(', ', $contactGroup[$prevContactID]['groupTitle']);
499 if ((!empty($contactGroup[$contactID]))) {
500 return $contactGroup[$contactID];
502 return $contactGroup;
506 * Get the datetime from which the cache should be considered invalid.
508 * Ie if the smartgroup cache timeout is 5 minutes ago then the cache is invalid if it was
509 * refreshed 6 minutes ago, but not if it was refreshed 4 minutes ago.
513 public static function getCacheInvalidDateTime(): string {
514 return date('YmdHis', strtotime("-" . self
::smartGroupCacheTimeout() . " Minutes"));
518 * Invalidates the smart group cache for a particular group
519 * @param int $groupID - Group to invalidate
521 public static function invalidateGroupContactCache($groupID): void
{
522 CRM_Core_DAO
::executeQuery("UPDATE civicrm_group
523 SET cache_date = NULL
524 WHERE id = %1 AND (saved_search_id IS NOT NULL OR children IS NOT NULL)", [
525 1 => [$groupID, 'Positive'],
530 * @param array $savedSearch
531 * @param string $addSelect
532 * @param string $excludeClause
534 * @throws API_Exception
535 * @throws \Civi\API\Exception\NotImplementedException
536 * @throws CRM_Core_Exception
538 protected static function getApiSQL(array $savedSearch, string $addSelect, string $excludeClause) {
539 $apiParams = $savedSearch['api_params'] +
['select' => ['id'], 'checkPermissions' => FALSE];
540 $idField = SqlExpression
::convert($apiParams['select'][0], TRUE)->getAlias();
541 // Unless there's a HAVING clause, we don't care about other columns
542 if (empty($apiParams['having'])) {
543 $apiParams['select'] = array_slice($apiParams['select'], 0, 1);
545 /* @var $api \Civi\Api4\Generic\DAOGetAction */
546 $api = Request
::create($savedSearch['api_entity'], 'get', $apiParams);
547 $query = new Api4SelectQuery($api);
548 $query->forceSelectId
= FALSE;
549 $query->getQuery()->having("$idField $excludeClause");
550 $sql = $query->getSql();
551 // Place sql in a nested sub-query, otherwise HAVING is impossible on any field other than contact_id
552 return "SELECT $addSelect, `$idField` AS contact_id FROM ($sql) api_query";
556 * Get sql from a custom search.
558 * We split it up and store custom class
559 * so temp tables are not destroyed if they are used
561 * @param int $savedSearchID
562 * @param array $ssParams
563 * @param string $addSelect
564 * @param string $excludeClause
567 * @throws CRM_Core_Exception
569 protected static function getCustomSearchSQL($savedSearchID, array $ssParams, string $addSelect, string $excludeClause) {
570 $searchSQL = CRM_Contact_BAO_SearchCustom
::customClass($ssParams['customSearchID'], $savedSearchID)->contactIDs();
571 $searchSQL = str_replace('ORDER BY contact_a.id ASC', '', $searchSQL);
572 if (strpos($searchSQL, 'WHERE') === FALSE) {
573 $searchSQL .= " WHERE contact_a.id $excludeClause";
576 $searchSQL .= " AND contact_a.id $excludeClause";
578 return preg_replace("/^\s*SELECT /", "SELECT $addSelect, ", $searchSQL);
582 * Get array of sql from a saved query object group.
584 * @param int $savedSearchID
585 * @param array $ssParams
586 * @param string $addSelect
587 * @param string $excludeClause
590 * @throws \CRM_Core_Exception
591 * @throws \CiviCRM_API3_Exception
593 protected static function getQueryObjectSQL($savedSearchID, array $ssParams, string $addSelect, string $excludeClause) {
594 $returnProperties = NULL;
595 if (CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_SavedSearch', $savedSearchID, 'mapping_id')) {
596 $fv = CRM_Contact_BAO_SavedSearch
::getFormValues($savedSearchID);
597 $returnProperties = CRM_Core_BAO_Mapping
::returnProperties($fv);
599 $formValues = CRM_Contact_BAO_SavedSearch
::getFormValues($savedSearchID);
600 // CRM-17075 using the formValues in this way imposes extra logic and complexity.
601 // we have the where_clause and where tables stored in the saved_search table
602 // and should use these rather than re-processing the form criteria (which over-works
603 // the link between the form layer & the query layer too).
604 // It's hard to think of when you would want to use anything other than return
605 // properties = array('contact_id' => 1) here as the point would appear to be to
606 // generate the list of contact ids in the group.
607 // @todo review this to use values in saved_search table (preferably for 4.8).
609 = new CRM_Contact_BAO_Query(
610 $ssParams, $returnProperties, NULL,
614 $formValues['display_relationship_type'] ??
NULL,
615 $formValues['operator'] ??
'AND'
617 $query->_useDistinct
= FALSE;
618 $query->_useGroupBy
= FALSE;
619 $sqlParts = $query->getSearchSQLParts(
623 "contact_a.id $excludeClause"
625 $select = preg_replace("/^\s*SELECT /", "SELECT $addSelect, ", $sqlParts['select']);
627 return "$select {$sqlParts['from']} {$sqlParts['where']} {$sqlParts['group_by']} {$sqlParts['having']}";
631 * Build a temporary table for the contacts in the specified group.
633 * @param array $groupIDs
634 * Currently only one id is build but this has been written
635 * to make it easy to switch to multiple.
636 * @param CRM_Utils_SQL_TempTable $tempTableObject
638 * @throws \API_Exception
639 * @throws \CRM_Core_Exception
640 * @throws \CiviCRM_API3_Exception
642 protected static function buildGroupContactTempTable(array $groupIDs, $tempTableObject): void
{
643 $group = Group
::get(FALSE)->addWhere('id', 'IN', $groupIDs)
644 ->setSelect(['saved_search_id', 'children'])->execute()->first();
645 $groupID = (int) $group['id'];
647 if ($group['saved_search_id']) {
648 $ssParams = CRM_Contact_BAO_SavedSearch
::getSearchParams($group['saved_search_id']);
650 $excludeClause = "NOT IN (
651 SELECT contact_id FROM civicrm_group_contact
652 WHERE civicrm_group_contact.status = 'Removed'
653 AND civicrm_group_contact.group_id = $groupID )";
654 $addSelect = "$groupID AS group_id";
656 if (!empty($ssParams['api_entity'])) {
657 $sql = self
::getApiSQL($ssParams, $addSelect, $excludeClause);
660 // CRM-7021 rectify params to what proximity search expects if there is a value for prox_distance
661 if (!empty($ssParams)) {
662 CRM_Contact_BAO_ProximityQuery
::fixInputParams($ssParams);
664 if (isset($ssParams['customSearchID'])) {
665 $sql = self
::getCustomSearchSQL($group['saved_search_id'], $ssParams, $addSelect, $excludeClause);
668 $sql = self
::getQueryObjectSQL($group['saved_search_id'], $ssParams, $addSelect, $excludeClause);
673 $tempTableName = $tempTableObject->getName();
674 $tempTableObject->createWithColumns('contact_id int, group_id int, UNIQUE UI_contact_group (contact_id,group_id)');
677 $contactQueries[] = $sql;
679 // lets also store the records that are explicitly added to the group
680 // this allows us to skip the group contact LEFT JOIN
682 "SELECT $groupID as group_id, contact_id as contact_id
683 FROM civicrm_group_contact
684 WHERE civicrm_group_contact.status = 'Added' AND civicrm_group_contact.group_id = $groupID ";
686 self
::clearGroupContactCache($groupID);
688 foreach ($contactQueries as $contactQuery) {
689 CRM_Core_DAO
::executeQuery("INSERT IGNORE INTO $tempTableName (group_id, contact_id) {$contactQuery}");
692 CRM_Core_DAO
::reenableFullGroupByMode();
694 if ($group['children']) {
696 // Store a list of contacts who are removed from the parent group
697 $sqlContactsRemovedFromGroup = "
699 FROM civicrm_group_contact
700 WHERE civicrm_group_contact.status = 'Removed'
701 AND civicrm_group_contact.group_id = $groupID ";
702 $dao = CRM_Core_DAO
::executeQuery($sqlContactsRemovedFromGroup);
703 $removed_contacts = [];
704 while ($dao->fetch()) {
705 $removed_contacts[] = $dao->contact_id
;
708 $childrenIDs = explode(',', $group['children']);
709 foreach ($childrenIDs as $childID) {
710 $contactIDs = CRM_Contact_BAO_Group
::getMember($childID, FALSE);
711 // Unset each contact that is removed from the parent group
712 foreach ($removed_contacts as $removed_contact) {
713 unset($contactIDs[$removed_contact]);
715 if (empty($contactIDs)) {
716 // This child group has no contact IDs so we don't need to add them to
720 foreach ($contactIDs as $contactID => $dontCare) {
721 $values[] = "({$groupID},{$contactID})";
723 $str = implode(',', $values);
724 CRM_Core_DAO
::executeQuery("INSERT IGNORE INTO $tempTableName (group_id, contact_id) VALUES $str");
730 * Populate a temporary table with group ids and contact ids.
732 * Do not call this outside of core tested code - it WILL change.
734 * @param array[int] $groupIDs
735 * @param string $temporaryTable
737 * @throws \CiviCRM_API3_Exception
739 public static function populateTemporaryTableWithContactsInGroups(array $groupIDs, string $temporaryTable): void
{
740 $groups = civicrm_api3('Group', 'get', [
742 'id' => ['IN' => $groupIDs],
743 'saved_search_id' => ['>' => 0],
746 $smartGroups = array_keys($groups['values']);
749 SELECT DISTINCT group_contact.contact_id as contact_id
750 FROM civicrm_group_contact group_contact
751 WHERE group_contact.group_id IN (" . implode(', ', $groupIDs) . ")
752 AND group_contact.status = 'Added' ";
754 if (!empty($smartGroups)) {
755 CRM_Contact_BAO_GroupContactCache
::check($smartGroups);
756 $smartGroups = implode(',', $smartGroups);
759 SELECT smartgroup_contact.contact_id as contact_id
760 FROM civicrm_group_contact_cache smartgroup_contact
761 WHERE smartgroup_contact.group_id IN ({$smartGroups}) ";
763 CRM_Core_DAO
::executeQuery('INSERT INTO ' . $temporaryTable . ' ' . $query);
767 * @param array|null $groupIDs
772 protected static function getGroupsNeedingRefreshing(?
array $groupIDs, int $limit): array {
773 $groupIDClause = NULL;
774 // ensure that all the smart groups are loaded
775 // this function is expensive and should be sparingly used if groupIDs is empty
776 if (!empty($groupIDs)) {
777 // note escapeString is a must here and we can't send the imploded value as second argument to
778 // the executeQuery(), since that would put single quote around the string and such a string
779 // of comma separated integers would not work.
780 $groupIDString = CRM_Core_DAO
::escapeString(implode(', ', $groupIDs));
781 $groupIDClause = "g.id IN ({$groupIDString})";
784 $query = self
::groupRefreshedClause($groupIDClause);
786 $limitClause = $orderClause = NULL;
788 $limitClause = " LIMIT 0, $limit";
789 $orderClause = " ORDER BY g.cache_date";
791 // We ignore hidden groups and disabled groups
797 $dao = CRM_Core_DAO
::executeQuery($query);
798 $processGroupIDs = [];
799 while ($dao->fetch()) {
800 $processGroupIDs[] = $dao->id
;
802 return $processGroupIDs;