Skip to content

Commit

Permalink
Merge pull request #16311 from MegaphoneJon/event-template-reminders
Browse files Browse the repository at this point in the history
event#28: Don't send scheduled reminders for event templates
  • Loading branch information
eileenmcnaughton authored Jan 23, 2020
2 parents fab0f46 + 5b4d40a commit eeda8cb
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
23 changes: 22 additions & 1 deletion Civi/ActionSchedule/RecipientBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function __construct($now, $actionSchedule, $mapping) {
public function build() {
$this->buildRelFirstPass();

if ($this->prepareAddlFilter('c.id')) {
if ($this->prepareAddlFilter('c.id') && $this->notTemplate()) {
$this->buildAddlFirstPass();
}

Expand Down Expand Up @@ -603,4 +603,25 @@ protected function resetOnTriggerDateChange() {
return $this->mapping->resetOnTriggerDateChange($this->actionSchedule);
}

/**
* Confirm this object isn't attached to a template.
* Returns TRUE if this action schedule isn't attached to a template.
* Templates are (currently) unique to events, so we only evaluate those.
*
* @return bool;
*/
private function notTemplate() {
if ($this->mapping->getEntity() === 'civicrm_participant') {
$entityId = $this->actionSchedule->entity_value;
$query = new \CRM_Utils_SQL_Select('civicrm_event e');
$sql = $query
->select('is_template')
->where("e.id = {$entityId}")
->toSQL();
$dao = \CRM_Core_DAO::executeQuery($sql);
return !(bool) $dao->fetchValue();
}
return TRUE;
}

}
32 changes: 32 additions & 0 deletions tests/phpunit/api/v3/JobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,38 @@ public function testCallDisableExpiredRelationships() {
$this->contactDelete($orgID);
}

/**
* Event templates should not send reminders to additional contacts.
*/
public function testTemplateRemindAddlContacts() {
$contactId = $this->individualCreate();
$groupId = $this->groupCreate(['name' => 'Additional Contacts', 'title' => 'Additional Contacts']);
$this->callAPISuccess('GroupContact', 'create', [
'contact_id' => $contactId,
'group_id' => $groupId,
]);
$event = $this->eventCreate(['is_template' => 1, 'template_title' => "I'm a template", 'title' => NULL]);
$eventId = $event['id'];

$actionSchedule = $this->callAPISuccess('action_schedule', 'create', [
'title' => "Do not send me",
'subject' => "I am a reminder attached to a template.",
'entity_value' => $eventId,
'mapping_id' => 5,
'start_action_date' => 'start_date',
'start_action_offset' => 1,
'start_action_condition' => 'before',
'start_action_unit' => 'day',
'group_id' => $groupId,
'limit_to' => FALSE,
'mode' => 'Email',
]);

$this->callAPISuccess('job', 'send_reminder', []);
$successfulCronCount = CRM_Core_DAO::singleValueQuery("SELECT count(*) FROM civicrm_action_log");
$this->assertEquals(0, $successfulCronCount);
}

/**
* Test scheduled reminders respect limit to (since above identified addition_to handling issue).
*
Expand Down

0 comments on commit eeda8cb

Please sign in to comment.