diff --git a/Civi/ActionSchedule/RecipientBuilder.php b/Civi/ActionSchedule/RecipientBuilder.php index c52f64adbb65..e04a4fbe3466 100644 --- a/Civi/ActionSchedule/RecipientBuilder.php +++ b/Civi/ActionSchedule/RecipientBuilder.php @@ -409,6 +409,8 @@ protected function prepareStartDateClauses() { else { $startDateClauses[] = "DATE_SUB(!casNow, INTERVAL 1 DAY ) <= {$date}"; } + $startDateClauses[] = "(effective_start_date IS NULL OR effective_start_date <= {$date})"; + $startDateClauses[] = "(effective_end_date IS NULL OR effective_end_date > {$date})"; } elseif ($actionSchedule->absolute_date) { $startDateClauses[] = "DATEDIFF(DATE('!casNow'),'{$actionSchedule->absolute_date}') = 0"; diff --git a/tests/phpunit/CRM/Core/BAO/ActionScheduleTest.php b/tests/phpunit/CRM/Core/BAO/ActionScheduleTest.php index 21d96074e50a..952a83ba83f3 100644 --- a/tests/phpunit/CRM/Core/BAO/ActionScheduleTest.php +++ b/tests/phpunit/CRM/Core/BAO/ActionScheduleTest.php @@ -153,6 +153,8 @@ public function setUp(): void { 'start_action_offset' => '1', 'start_action_unit' => 'day', 'subject' => '1-Day (non-repeating) (about {activity.activity_type})', + 'effective_start_date' => '2012-06-14 00:00:00', + 'effective_end_date' => '2012-06-15 00:00:00', ]; $this->fixtures['sched_activity_1day_r'] = [ 'name' => 'One_Day_Phone_Call_Notice_R', @@ -183,6 +185,7 @@ public function setUp(): void { 'start_action_offset' => '1', 'start_action_unit' => 'day', 'subject' => '1-Day (repeating) (about {activity.activity_type})', + 'effective_end_date' => '2012-06-14 01:00:01', ]; $this->fixtures['sched_activity_1day_r_on_abs_date'] = [ 'name' => 'One_Day_Phone_Call_Notice_R', @@ -2065,6 +2068,56 @@ public function testEventTypeStartDate(): void { 'recipients' => [], ], ]); + + // CASE 2: Create a schedule reminder which was created 1 day after the schdule day, + // so it shouldn't deliver reminders schedule to send 1 week before the event start date + $actionSchedule = $this->fixtures['sched_eventtype_start_1week_before']; + $actionSchedule['entity_value'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $participant->event_id, 'event_type_id'); + $actionSchedule['effective_start_date'] = '20120309000000'; + $this->callAPISuccess('action_schedule', 'create', $actionSchedule); + // end_date=2012-06-15 ; schedule is 2 weeks before end_date + $this->assertCronRuns([ + [ + // 2 weeks before + 'time' => '2012-03-02 01:00:00', + 'recipients' => [], + ], + [ + // 1 week before + 'time' => '2012-03-08 01:00:00', + 'recipients' => [], + ], + [ + // And then nothing else + 'time' => '2012-03-16 01:00:00', + 'recipients' => [], + ], + ]); + + // CASE 3: Create a schedule reminder which is created less then a week before the event start date, + // so it should deliver reminders schedule to send 1 week before the event start date, set the effective end date just an hour later the reminder delivery date + $actionSchedule = $this->fixtures['sched_eventtype_start_1week_before']; + $actionSchedule['entity_value'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $participant->event_id, 'event_type_id'); + $actionSchedule['effective_end_date'] = '20120309010000'; + $this->callAPISuccess('action_schedule', 'create', $actionSchedule); + // end_date=2012-06-15 ; schedule is 2 weeks before end_date + $this->assertCronRuns([ + [ + // 2 weeks before + 'time' => '2012-03-02 01:00:00', + 'recipients' => [], + ], + [ + // 1 week before + 'time' => '2012-03-08 01:00:00', + 'recipients' => [['test-event@example.com']], + ], + [ + // And then nothing else + 'time' => '2012-03-16 01:00:00', + 'recipients' => [], + ], + ]); } /**