// Freeze gradebook calculations if needed.
$this->gradebook_calculation_freeze();
+ // Ensure the module cache is current when recalculating grades.
+ rebuild_course_cache($this->get_courseid(), true);
+
// Restore marks items as needing update. Update everything now.
grade_regrade_final_grades($this->get_courseid());
}
*/
public function get_context() {
if ($this->itemtype == 'mod') {
- $cm = get_fast_modinfo($this->courseid)->instances[$this->itemmodule][$this->iteminstance];
- $context = \context_module::instance($cm->id);
+ $modinfo = get_fast_modinfo($this->courseid);
+ // Sometimes the course module cache is out of date and needs to be rebuilt.
+ if (!isset($modinfo->instances[$this->itemmodule][$this->iteminstance])) {
+ rebuild_course_cache($this->courseid, true);
+ $modinfo = get_fast_modinfo($this->courseid);
+ }
+ // Even with a rebuilt cache the module does not exist. This means the
+ // database is in an invalid state - we will log an error and return
+ // the course context but the calling code should be updated.
+ if (!isset($modinfo->instances[$this->itemmodule][$this->iteminstance])) {
+ mtrace(get_string('moduleinstancedoesnotexist', 'error'));
+ $context = \context_course::instance($this->courseid);
+ } else {
+ $cm = $modinfo->instances[$this->itemmodule][$this->iteminstance];
+ $context = \context_module::instance($cm->id);
+ }
} else {
$context = \context_course::instance($this->courseid);
}
}
// Delete the instance.
+ // We must delete the module record after we delete the grade item.
$DB->delete_records('assign', array('id'=>$this->get_instance()->id));
return $result;
$result = false;
}
+ grade_update('mod/assignment', $assignment->course, 'mod', 'assignment', $assignment->id, 0, NULL, array('deleted'=>1));
+
+ // We must delete the module record after we delete the grade item.
if (! $DB->delete_records('assignment', array('id'=>$assignment->id))) {
$result = false;
}
- grade_update('mod/assignment', $assignment->course, 'mod', 'assignment', $assignment->id, 0, NULL, array('deleted'=>1));
-
return $result;
}
$event->delete();
}
- // Delete the instance itself
- $result = $DB->delete_records('data', array('id'=>$id));
-
// cleanup gradebook
data_grade_item_delete($data);
+ // Delete the instance itself
+ // We must delete the module record after we delete the grade item.
+ $result = $DB->delete_records('data', array('id'=>$id));
+
return $result;
}
forum_tp_delete_read_records(-1, -1, -1, $forum->id);
+ forum_grade_item_delete($forum);
+
+ // We must delete the module record after we delete the grade item.
if (!$DB->delete_records('forum', array('id'=>$forum->id))) {
$result = false;
}
- forum_grade_item_delete($forum);
-
return $result;
}
$this->delete_all_overrides();
+ grade_update('mod/lesson', $this->properties->course, 'mod', 'lesson', $this->properties->id, 0, null, array('deleted'=>1));
+
+ // We must delete the module record after we delete the grade item.
$DB->delete_records("lesson", array("id"=>$this->properties->id));
$DB->delete_records("lesson_pages", array("lessonid"=>$this->properties->id));
$DB->delete_records("lesson_answers", array("lessonid"=>$this->properties->id));
$fs = get_file_storage();
$fs->delete_area_files($context->id);
- grade_update('mod/lesson', $this->properties->course, 'mod', 'lesson', $this->properties->id, 0, null, array('deleted'=>1));
return true;
}
$cm = get_coursemodule_from_instance('lti', $id);
\core_completion\api::update_completion_date_event($cm->id, 'lti', $id, null);
+ // We must delete the module record after we delete the grade item.
return $DB->delete_records("lti", array("id" => $basiclti->id));
}
}
quiz_grade_item_delete($quiz);
+ // We must delete the module record after we delete the grade item.
$DB->delete_records('quiz', array('id' => $quiz->id));
return true;
}
$DB->delete_records('scorm_scoes', array('scorm' => $scorm->id));
}
+
+ scorm_grade_item_delete($scorm);
+
+ // We must delete the module record after we delete the grade item.
if (! $DB->delete_records('scorm', array('id' => $scorm->id))) {
$result = false;
}
$result = false;
}*/
- scorm_grade_item_delete($scorm);
-
return $result;
}
$event->delete();
}
- // finally remove the workshop record itself
- $DB->delete_records('workshop', array('id' => $workshop->id));
-
// gradebook cleanup
grade_update('mod/workshop', $workshop->course, 'mod', 'workshop', $workshop->id, 0, null, array('deleted' => true));
grade_update('mod/workshop', $workshop->course, 'mod', 'workshop', $workshop->id, 1, null, array('deleted' => true));
+ // finally remove the workshop record itself
+ // We must delete the module record after we delete the grade item.
+ $DB->delete_records('workshop', array('id' => $workshop->id));
+
return true;
}