Skip to content
Browse files

Merge branch 'MDL-29877_bad_grade_item_24' of git://github.com/andyjd…

…avis/moodle into MOODLE_24_STABLE

Conflicts:
	version.php
  • Loading branch information...
2 parents 7ec3994 + 166102e commit d4a997b7d7a902c2df0565fa548c73f068e735ee @damyon damyon committed
Showing with 16 additions and 2 deletions.
  1. +10 −0 lib/db/upgrade.php
  2. +6 −2 lib/grade/grade_category.php
View
10 lib/db/upgrade.php
@@ -1687,5 +1687,15 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2012120303.02);
}
+ if ($oldversion < 2012120301.18) {
+ // 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, 2012120301.18);
+ }
+
return true;
}
View
8 lib/grade/grade_category.php
@@ -1154,13 +1154,17 @@ public function get_children($include_category_items=false) {
} else {
$categoryid = $item->categoryid;
+ if (empty($categoryid)) {
+ debugging('Found a grade item that isnt in a category');
+ }
}
// prevent problems with duplicate sortorders in db
$sortorder = $item->sortorder;
- while (array_key_exists($sortorder, $cats[$categoryid]->children)) {
- //debugging("$sortorder exists in item loop");
+ while (array_key_exists($categoryid, $cats)
+ && array_key_exists($sortorder, $cats[$categoryid]->children)) {
+
$sortorder++;
}

0 comments on commit d4a997b

Please sign in to comment.
Something went wrong with that request. Please try again.