Merge branch 'MDL-77091-400' of https://github.com/paulholden/moodle into MOODLE_400_STABLE

This commit is contained in:
Andrew Nicols
2023-02-06 12:59:46 +08:00
4 changed files with 14 additions and 4 deletions
@@ -44,13 +44,14 @@ class schedule {
* Create report schedule, calculate when it should be next sent
*
* @param stdClass $data
* @param int|null $timenow Time to use as comparison against current date (defaults to current time)
* @return model
*/
public static function create_schedule(stdClass $data): model {
public static function create_schedule(stdClass $data, ?int $timenow = null): model {
$data->name = trim($data->name);
$schedule = (new model(0, $data));
$schedule->set('timenextsend', self::calculate_next_send_time($schedule));
$schedule->set('timenextsend', self::calculate_next_send_time($schedule, $timenow));
return $schedule->create();
}
@@ -229,7 +230,7 @@ class schedule {
* returned value is after the current date
*
* @param model $schedule
* @param int|null $timenow Time to use for calculation (defaults to current time)
* @param int|null $timenow Time to use as comparison against current date (defaults to current time)
* @return int
*/
public static function calculate_next_send_time(model $schedule, ?int $timenow = null): int {
+4 -1
View File
@@ -198,6 +198,9 @@ class core_reportbuilder_generator extends component_generator_base {
$record['timescheduled'] = usergetmidnight(time() + DAYSECS);
}
return schedule_helper::create_schedule((object) $record);
// Time to use as comparison against current date (null means current time).
$timenow = $record['timenow'] ?? null;
return schedule_helper::create_schedule((object) $record, $timenow);
}
}
@@ -404,6 +404,7 @@ class schedule_test extends advanced_testcase {
'name' => 'My schedule',
'recurrence' => $recurrence,
'timescheduled' => $timescheduled,
'timenow' => $timenow,
]);
$this->assertEquals($expected, schedule::calculate_next_send_time($schedule, $timenow));
+5
View File
@@ -1,6 +1,11 @@
This file describes API changes in /reportbuilder/*
Information provided here is intended especially for developers.
=== 4.0.7 ===
* The schedule helper `create_schedule` method accepts a `$timenow` parameter to use for comparisons against current date
during tests
=== 4.0.6 ===
* The `datasource_stress_test_columns` test helper now enables sorting on those columns that support it