Merge branch 'MDL-29877_bad_grade_item_24' of git://github.com/andyjdavis/moodle into MOODLE_24_STABLE

Conflicts:
	version.php
This commit is contained in:
Damyon Wiese
2013-04-12 11:36:17 +08:00
2 changed files with 16 additions and 2 deletions
+10
View File
@@ -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;
}
+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++;
}