Skip to content

Commit

Permalink
MDL-74106 reportbuilder: handle non-recurring schedules properly.
Browse files Browse the repository at this point in the history
When a schedule is created with "No recurrence", it should only be
sent when both conditions are true: it's start time is after the
current time; and the time it was last sent is before it's start
time (either 0/never sent; or a time it was manually sent).
  • Loading branch information
paulholden committed Mar 7, 2022
1 parent 1d99ba1 commit 2916f89
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
8 changes: 7 additions & 1 deletion reportbuilder/classes/local/helpers/schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,13 @@ public static function should_send_schedule(model $schedule): bool {
return false;
}

return $schedule->get('timenextsend') <= $timenow;
// If there's no recurrence, check whether it's been sent since initial scheduled start time. This ensures that even if
// the schedule was manually sent beforehand, it'll still be automatically sent once the start time is first reached.
if ($schedule->get('recurrence') === model::RECURRENCE_NONE) {
return $schedule->get('timelastsent') < $timescheduled;
}

return $schedule->get('timenextsend') <= $timenow;
}

/**
Expand Down
15 changes: 15 additions & 0 deletions reportbuilder/tests/local/helpers/schedule_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,25 @@ public function should_send_schedule_provider(): array {
'recurrence' => model::RECURRENCE_NONE,
'timescheduled' => $yesterday,
], true],
'Time scheduled in the past, already sent prior to schedule' => [[
'recurrence' => model::RECURRENCE_NONE,
'timescheduled' => $yesterday,
'timelastsent' => $yesterday - HOURSECS,
], true],
'Time scheduled in the past, already sent on schedule' => [[
'recurrence' => model::RECURRENCE_NONE,
'timescheduled' => $yesterday,
'timelastsent' => $yesterday,
], false],
'Time scheduled in the future' => [[
'recurrence' => model::RECURRENCE_NONE,
'timescheduled' => $tomorrow,
], false],
'Time scheduled in the future, already sent prior to schedule' => [[
'recurrence' => model::RECURRENCE_NONE,
'timelastsent' => $yesterday,
'timescheduled' => $tomorrow,
], false],
'Next send in the past' => [[
'recurrence' => model::RECURRENCE_DAILY,
'timescheduled' => $yesterday,
Expand Down

0 comments on commit 2916f89

Please sign in to comment.