Commit eb694bdd authored by Mikhail Golenkov's avatar Mikhail Golenkov

MDL-70520 tasks: Keep lastruntime when a scheduled task is reset

parent 4ec279a2
......@@ -229,6 +229,7 @@ class manager {
$record = self::record_from_scheduled_task($task);
$record->id = $original->id;
$record->nextruntime = $task->get_next_scheduled_time();
unset($record->lastruntime);
$result = $DB->update_record('task_scheduled', $record);
return $result;
......
......@@ -691,4 +691,24 @@ class core_scheduled_task_testcase extends advanced_testcase {
call_user_func_array([$this, 'assertNotEquals'], $args);
}
/**
* Assert that the lastruntime column holds an original value after a scheduled task is reset.
*/
public function test_reset_scheduled_tasks_for_component_keeps_original_lastruntime(): void {
global $DB;
$this->resetAfterTest(true);
// Set lastruntime for the scheduled task.
$DB->set_field('task_scheduled', 'lastruntime', 123456789, ['classname' => '\core\task\session_cleanup_task']);
// Reset the task.
\core\task\manager::reset_scheduled_tasks_for_component('moodle');
// Fetch the task again.
$taskafterreset = \core\task\manager::get_scheduled_task(core\task\session_cleanup_task::class);
// Confirm, that lastruntime is still in place.
$this->assertEquals(123456789, $taskafterreset->get_last_run_time());
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment