]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-13085 delete grades and items when uninstalling module; merged from MOODLE_19_STABLE
authorskodak <skodak>
Mon, 21 Jan 2008 23:36:19 +0000 (23:36 +0000)
committerskodak <skodak>
Mon, 21 Jan 2008 23:36:19 +0000 (23:36 +0000)
admin/modules.php
lib/gradelib.php

index 311b937fb8d8382b381e1b8861fb812ebf6a27a7..1050864500733dd592801e3797d0eaefa62a7763 100644 (file)
                 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);
 
index 444cb6c88b90c33e6e84112a4ef0e96c81d6b107..85c0ea1c62a5397f4ae9969e38f2f1474917c047 100644 (file)
@@ -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
  */