From 6cb6ba4c8146016e0476a12db1c0e5b5f9121f84 Mon Sep 17 00:00:00 2001 From: yashodha Date: Wed, 12 Jun 2013 15:12:33 +0530 Subject: [PATCH] CRM-12689 --- CRM/Core/BAO/ActionSchedule.php | 50 +++++++++++++++---- .../Incremental/sql/4.4.alpha1.mysql.tpl | 4 ++ 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/CRM/Core/BAO/ActionSchedule.php b/CRM/Core/BAO/ActionSchedule.php index 3d68aaddaa..4052032391 100755 --- a/CRM/Core/BAO/ActionSchedule.php +++ b/CRM/Core/BAO/ActionSchedule.php @@ -754,6 +754,7 @@ WHERE reminder.action_schedule_id = %1 AND reminder.action_date_time IS NULL if ($mapping->entity == 'civicrm_activity') { $contactField = 'r.contact_id'; + $table = 'civicrm_activity e'; $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts); $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); @@ -791,6 +792,7 @@ WHERE reminder.action_schedule_id = %1 AND reminder.action_date_time IS NULL } if ($mapping->entity == 'civicrm_participant') { + $table = 'civicrm_event r'; $contactField = 'e.contact_id'; $join[] = 'INNER JOIN civicrm_event r ON e.event_id = r.id'; if ($actionSchedule->recipient_listing) { @@ -829,7 +831,7 @@ WHERE reminder.action_schedule_id = %1 AND reminder.action_date_time IS NULL $notINClause = ''; if ($mapping->entity == 'civicrm_membership') { $contactField = 'e.contact_id'; - + $table = 'civicrm_membership e'; // build where clause if ( $status == 2 ) { //auto-renew memberships @@ -856,16 +858,27 @@ WHERE reminder.action_schedule_id = %1 AND reminder.action_date_time IS NULL $where[] = "e.status_id IN ({$mStatus})"; } - - 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})"; + 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})"; + } + elseif (!empty($actionSchedule->recipient_manual)) { + $rList = CRM_Utils_Type::escape($actionSchedule->recipient_manual, 'String'); + $where[] = "{$contactField} IN ({$rList})"; + } } - elseif (!empty($actionSchedule->recipient_manual)) { - $rList = CRM_Utils_Type::escape($actionSchedule->recipient_manual, 'String'); - $where[] = "{$contactField} IN ({$rList})"; + else { + 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})"; + } + if (!empty($actionSchedule->recipient_manual)) { + $rList = CRM_Utils_Type::escape($actionSchedule->recipient_manual, 'String'); + $addWhere = "c.id IN ({$rList})"; + } + } - $select[] = "{$contactField} as contact_id"; $select[] = 'e.id as entity_id'; $select[] = "'{$mapping->entity}' as entity_table"; @@ -904,14 +917,29 @@ reminder.action_schedule_id = %1"; $fromClause = "FROM $from"; $joinClause = !empty($join) ? implode(' ', $join) : ''; $whereClause = 'WHERE ' . implode(' AND ', $where); - + $union = ''; + + if ($limitTo == 0) { + $union =" +UNION + SELECT c.id as contact_id, c.id as entity_id, 'civicrm_contact' as entity_table, {$actionSchedule->id} as action_schedule_id +FROM (civicrm_contact c, {$table}) +LEFT JOIN civicrm_action_log reminder ON reminder.contact_id = c.id AND + reminder.entity_id = c.id AND + reminder.entity_table = 'civicrm_contact' AND + reminder.action_schedule_id = {$actionSchedule->id} +{$addGroup} +WHERE (reminder.id IS NULL AND c.is_deleted = 0 AND c.is_deceased = 0 AND {$addWhere})AND + {$dateClause}"; + } $query = " INSERT INTO civicrm_action_log (contact_id, entity_id, entity_table, action_schedule_id) {$selectClause} {$fromClause} {$joinClause} LEFT JOIN {$reminderJoinClause} -{$whereClause} AND {$dateClause} {$notINClause}"; +{$whereClause} AND {$dateClause} {$notINClause} + {$union}"; CRM_Core_DAO::executeQuery($query, array(1 => array($actionSchedule->id, 'Integer'))); diff --git a/CRM/Upgrade/Incremental/sql/4.4.alpha1.mysql.tpl b/CRM/Upgrade/Incremental/sql/4.4.alpha1.mysql.tpl index 04b3a5edeb..07fd55a3e8 100644 --- a/CRM/Upgrade/Incremental/sql/4.4.alpha1.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/4.4.alpha1.mysql.tpl @@ -51,3 +51,7 @@ VALUES {else} UPDATE civicrm_option_value SET label ='Outbound SMS' WHERE name = 'SMS' and option_group_id = @option_group_id_activity_type; {/if} + +-- CRM-12689 +ALTER TABLE civicrm_action_schedule + ADD COLUMN limit_to tinyint(4) DEFAULT '1' COMMENT 'Is this the recipient criteria limited to OR in addition to?' AFTER recipient; -- 2.25.1