MDL-29877 core_grade:add some upgrade code to fix broken grade items introduced by bad restores

This commit is contained in:
Andrew Davis
2013-04-10 08:05:50 +08:00
parent 422f68fb86
commit 63354ab50d
3 changed files with 17 additions and 3 deletions
+10
View File
@@ -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;
}
+6 -2
View File
@@ -1154,13 +1154,17 @@ class grade_category extends grade_object {
} 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++;
}
+1 -1
View File
@@ -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