Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-29877 core_grade:add some upgrade code to fix broken grade items …

…introduced by bad restores
  • Loading branch information...
commit 63354ab50d5ecd97228a609a24c0a3bb4b915bcc 1 parent 422f68f
Andrew Davis andyjdavis authored
Showing with 17 additions and 3 deletions.
  1. +10 −0 lib/db/upgrade.php
  2. +6 −2 lib/grade/grade_category.php
  3. +1 −1  version.php
10 lib/db/upgrade.php
View
@@ -1990,5 +1990,15 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2013040300.01);
}
+ if ($oldversion < 2013040500.01) {
+ // 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, 2013040500.01);
+ }
+
return true;
}
8 lib/grade/grade_category.php
View
@@ -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++;
}
2  version.php
View
@@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
-$version = 2013040500.00; // YYYYMMDD = weekly release date of this DEV branch
+$version = 2013040500.01; // YYYYMMDD = weekly release date of this DEV branch
// RR = release increments - 00 in DEV branches
// .XX = incremental changes
Please sign in to comment.
Something went wrong with that request. Please try again.