Permalink
Browse files

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

…avis/moodle into MOODLE_23_STABLE

Conflicts:
	version.php
  • Loading branch information...
2 parents 7bfe54c + aeacefd commit d3b880b578e56a599830665b85342bc91891fb8a @damyon damyon committed Apr 12, 2013
Showing with 16 additions and 2 deletions.
  1. +10 −0 lib/db/upgrade.php
  2. +6 −2 lib/grade/grade_category.php
View
@@ -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;
}
@@ -1152,13 +1152,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 d3b880b

Please sign in to comment.