diff --git a/lib/classes/task/manager.php b/lib/classes/task/manager.php index 559c68f7676..0c28dd61726 100644 --- a/lib/classes/task/manager.php +++ b/lib/classes/task/manager.php @@ -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; diff --git a/lib/tests/scheduled_task_test.php b/lib/tests/scheduled_task_test.php index a16e8e0bb48..aa03f51f59e 100644 --- a/lib/tests/scheduled_task_test.php +++ b/lib/tests/scheduled_task_test.php @@ -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()); + } }