From 8a0a6046a3b0fca47bf6131133e52d080fbb2291 Mon Sep 17 00:00:00 2001 From: skodak Date: Mon, 21 Jan 2008 23:36:19 +0000 Subject: [PATCH] MDL-13085 delete grades and items when uninstalling module; merged from MOODLE_19_STABLE --- admin/modules.php | 4 ++++ lib/gradelib.php | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/admin/modules.php b/admin/modules.php index 311b937fb8..1050864500 100644 --- a/admin/modules.php +++ b/admin/modules.php @@ -144,6 +144,10 @@ notify("Error occurred while deleting the $strmodulename records from the config table"); } + // cleanup the gradebook + require_once($CFG->libdir.'/gradelib.php'); + grade_uninstalled_module($module->name); + // Then the tables themselves drop_plugin_tables($module->name, "$CFG->dirroot/mod/$module->name/db/install.xml", false); diff --git a/lib/gradelib.php b/lib/gradelib.php index 444cb6c88b..85c0ea1c62 100644 --- a/lib/gradelib.php +++ b/lib/gradelib.php @@ -1135,6 +1135,26 @@ function remove_course_grades($courseid, $showfeedback) { } } +/** + * Does gradebook cleanup when module uninstalled. + */ +function grade_uninstalled_module($modname) { + global $CFG; + + $sql = "SELECT * + FROM {$CFG->prefix}grade_items + WHERE itemtype='mod' AND itemmodule='$modname'"; + + // go all items for this module and delete them including the grades + if ($rs = get_recordset_sql($sql)) { + while ($item = rs_fetch_next_record($rs)) { + $grade_item = new grade_item($item, false); + $grade_item->delete('moduninstall'); + } + rs_close($rs); + } +} + /** * Grading cron job */ -- 2.39.5