MDL-29877 core_grade:add some upgrade code to fix broken grade items introduced by...
[moodle.git] / lib / db / upgrade.php
index 6233a52..5ff29f7 100644 (file)
@@ -1142,5 +1142,15 @@ function xmldb_main_upgrade($oldversion) {
         upgrade_main_savepoint(true, 2012062506.02);
     }
 
+    if ($oldversion < 2012062506.04) {
+        // MDL-29877 Some bad restores created grade items with no category information.
+        $sql = "UPDATE mdl_grade_items
+                   SET categoryid = courseid
+                 WHERE itemtype <> 'course' and itemtype <> 'category'
+                       AND categoryid IS NULL";
+        $DB->execute($sql);
+        upgrade_main_savepoint(true, 2012062506.04);
+    }
+
     return true;
 }