MDL-64878 grades: Update delete_instance

When grades are deleted, it needs to know the context so any files
in the gradebook can be deleted. This means module delete_instance
functions must delete the grade_item before they delete the module record.
This commit is contained in:
Damyon Wiese
2019-02-27 10:40:02 +08:00
parent 1a3faa11b7
commit 7cd7f20202
9 changed files with 24 additions and 13 deletions
+1
View File
@@ -783,6 +783,7 @@ class assign {
}
// 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;
+3 -2
View File
@@ -71,12 +71,13 @@ function assignment_delete_instance($id){
$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;
}
+4 -3
View File
@@ -1153,12 +1153,13 @@ function data_delete_instance($id) { // takes the dataid
$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;
}
+3 -2
View File
@@ -305,12 +305,13 @@ function forum_delete_instance($id) {
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;
}
+3 -1
View File
@@ -1637,6 +1637,9 @@ class lesson extends lesson_base {
$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));
@@ -1657,7 +1660,6 @@ class lesson extends lesson_base {
$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;
}
+1
View File
@@ -200,6 +200,7 @@ function lti_delete_instance($id) {
$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));
}
+1
View File
@@ -203,6 +203,7 @@ function quiz_delete_instance($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;
+4 -2
View File
@@ -301,6 +301,10 @@ function scorm_delete_instance($id) {
}
$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;
}
@@ -327,8 +331,6 @@ function scorm_delete_instance($id) {
$result = false;
}*/
scorm_grade_item_delete($scorm);
return $result;
}
+4 -3
View File
@@ -290,13 +290,14 @@ function workshop_delete_instance($id) {
$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;
}