diff --git a/classes/reporter.php b/classes/reporter.php index 51ebbba..fe1e9df 100644 --- a/classes/reporter.php +++ b/classes/reporter.php @@ -136,7 +136,7 @@ public function get_diagnosis() { * * @return array of diagnosis */ - private function get_diagnosis_data(array $taskids = null) { + private function get_diagnosis_data(?array $taskids = null) { $diagnoses = array(); $deletetaskslist = new delete_task_list($this->minimumfaildelay); $deletetasks = $deletetaskslist->get_deletetasks(); diff --git a/classes/surgeon.php b/classes/surgeon.php index 3f18150..89815a9 100644 --- a/classes/surgeon.php +++ b/classes/surgeon.php @@ -310,7 +310,13 @@ private function delete_module_cleanly(diagnosis $diagnosis) { } // Notify the competency subsystem. - \core_competency\api::hook_course_module_deleted($cm); + // The function hook_course_module_deleted() deletes the module context in 5.1+. + // context_module::instance($cm->id); causes dml_missing_record_exception when the course_modules record is already absent. + try { + \core_competency\api::hook_course_module_deleted($cm); + } catch (\dml_missing_record_exception $e) { + // Context no longer exists; competency data already cleaned up or not present. + } // Delete the context. if ($modcontext) {