Skip to content

Commit

Permalink
MDL-64878 grades: Update delete_instance
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Damyon Wiese committed Feb 27, 2019
1 parent 031cf25 commit 40fe153
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 13 deletions.
1 change: 1 addition & 0 deletions mod/assign/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,7 @@ public function delete_instance() {
}

// 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;
Expand Down
5 changes: 3 additions & 2 deletions mod/assignment/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
7 changes: 4 additions & 3 deletions mod/data/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
5 changes: 3 additions & 2 deletions mod/forum/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 3 additions & 1 deletion mod/lesson/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1642,6 +1642,9 @@ public function delete() {

$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));
Expand All @@ -1662,7 +1665,6 @@ public function delete() {
$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;
}

Expand Down
1 change: 1 addition & 0 deletions mod/lti/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
1 change: 1 addition & 0 deletions mod/quiz/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions mod/scorm/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -327,8 +331,6 @@ function scorm_delete_instance($id) {
$result = false;
}*/

scorm_grade_item_delete($scorm);

return $result;
}

Expand Down
7 changes: 4 additions & 3 deletions mod/workshop/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 40fe153

Please sign in to comment.