From f10c69fa62c3d5d29181c75a3aa1d2f0fd1b51f1 Mon Sep 17 00:00:00 2001 From: "Donald A. Lobo" Date: Mon, 21 Oct 2013 13:10:14 -0700 Subject: [PATCH] CRM-13577 - cleanup vedaconsulting patch and PR - 1821 ---------------------------------------- * CRM-13577: Allow Smart Groups in Scheduled Reminders http://issues.civicrm.org/jira/browse/CRM-13577 --- CRM/Admin/Form/ScheduleReminders.php | 8 +++-- CRM/Core/BAO/ActionSchedule.php | 48 +++++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/CRM/Admin/Form/ScheduleReminders.php b/CRM/Admin/Form/ScheduleReminders.php index 40bce4d533..ab33813b5f 100644 --- a/CRM/Admin/Form/ScheduleReminders.php +++ b/CRM/Admin/Form/ScheduleReminders.php @@ -207,8 +207,12 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form { $this->assign('tokenUrl', $tokenUrl); $this->add('text', 'recipient_manual_id', ts('Manual Recipients')); - $this->addElement('select', 'group_id', ts('Group'), - CRM_Core_PseudoConstant::staticGroup() + $this->addElement( + 'select', + 'group_id', + ts('Group'), + // CRM-13577 + CRM_Core_PseudoConstant::group() ); CRM_Mailing_BAO_Mailing::commonCompose($this); diff --git a/CRM/Core/BAO/ActionSchedule.php b/CRM/Core/BAO/ActionSchedule.php index 94ceaca46d..9ba855f6ea 100755 --- a/CRM/Core/BAO/ActionSchedule.php +++ b/CRM/Core/BAO/ActionSchedule.php @@ -898,10 +898,44 @@ WHERE reminder.action_schedule_id = %1 AND reminder.action_date_time IS NULL $where[] = "e.status_id IN ({$mStatus})"; } + // CRM-13577 Introduce Smart Groups Handling + if ($actionSchedule->group_id) { + + // Need to check if its a smart group or not + // Then decide which table to join onto the query + $group = CRM_Contact_DAO_Group::getTableName(); + + // Get the group information + $sql = " +SELECT $group.id, $group.cache_date, $group.saved_search_id, $group.children +FROM $group +WHERE $group.id = {$actionSchedule->group_id} +"; + + $groupDAO = CRM_Core_DAO::executeQuery($sql); + $isSmartGroup = FALSE; + if ( + $groupDAO->fetch() && + !empty($groupDAO->saved_search_id) + ) { + // Check that the group is in place in the cache and up to date + CRM_Contact_BAO_GroupContactCache::check($actionSchedule->group_id); + // Set smart group flag + $isSmartGroup = TRUE; + } + } + // CRM-13577 End Introduce Smart Groups Handling + if ($limitTo) { if ($actionSchedule->group_id) { - $join[] = "INNER JOIN civicrm_group_contact grp ON {$contactField} = grp.contact_id AND grp.status = 'Added'"; - $where[] = "grp.group_id IN ({$actionSchedule->group_id})"; + // CRM-13577 If smart group then use Cache table + if ($isSmartGroup) { + $join[] = "INNER JOIN civicrm_group_contact_cache grp ON {$contactField} = grp.contact_id"; + $where[] = "grp.group_id IN ({$actionSchedule->group_id})"; + } else { + $join[] = "INNER JOIN civicrm_group_contact grp ON {$contactField} = grp.contact_id AND grp.status = 'Added'"; + $where[] = "grp.group_id IN ({$actionSchedule->group_id})"; + } } elseif (!empty($actionSchedule->recipient_manual)) { $rList = CRM_Utils_Type::escape($actionSchedule->recipient_manual, 'String'); @@ -911,8 +945,14 @@ WHERE reminder.action_schedule_id = %1 AND reminder.action_date_time IS NULL else { $addGroup = $addWhere = ''; if ($actionSchedule->group_id) { - $addGroup = " INNER JOIN civicrm_group_contact grp ON c.id = grp.contact_id AND grp.status = 'Added'"; - $addWhere = " grp.group_id IN ({$actionSchedule->group_id})"; + // CRM-13577 If smart group then use Cache table + if ($isSmartGroup) { + $addGroup = " INNER JOIN civicrm_group_contact_cache grp ON c.id = grp.contact_id"; + $addWhere = " grp.group_id IN ({$actionSchedule->group_id})"; + } else { + $addGroup = " INNER JOIN civicrm_group_contact grp ON c.id = grp.contact_id AND grp.status = 'Added'"; + $addWhere = " grp.group_id IN ({$actionSchedule->group_id})"; + } } if (!empty($actionSchedule->recipient_manual)) { $rList = CRM_Utils_Type::escape($actionSchedule->recipient_manual, 'String'); -- 2.25.1