Permalink
Browse files

MDL-31314 gradebook restore: fix category.depth on restore.

Without this, restoring backups made with the OU's custom 'restore from
1.9' feature, and possibly other people's custom converstion code, does
not work properly.

Also, fix poor recordset code.
  • Loading branch information...
1 parent d4b3034 commit a3b0c9462f050904d0b279aa703b03abb3b0fbe2 @timhunt timhunt committed Jan 20, 2012
Showing with 16 additions and 21 deletions.
  1. +16 −21 backup/moodle2/restore_stepslib.php
View
37 backup/moodle2/restore_stepslib.php
@@ -371,40 +371,35 @@ protected function after_execute() {
}
$rs->close();
- //need to correct the grade category path and parent
+ // Need to correct the grade category path and parent
$conditions = array(
'courseid' => $this->get_courseid()
);
- $grade_category = new stdclass();
$rs = $DB->get_recordset('grade_categories', $conditions);
- if (!empty($rs)) {
- //get all the parents correct first as grade_category::build_path() loads category parents from the DB
- foreach($rs as $gc) {
- if (!empty($gc->parent)) {
- $grade_category->id = $gc->id;
- $grade_category->parent = $this->get_mappingid('grade_category', $gc->parent);
- $DB->update_record('grade_categories', $grade_category);
- }
+ // Get all the parents correct first as grade_category::build_path() loads category parents from the DB
+ foreach ($rs as $gc) {
+ if (!empty($gc->parent)) {
+ $grade_category = new stdClass();
+ $grade_category->id = $gc->id;
+ $grade_category->parent = $this->get_mappingid('grade_category', $gc->parent);
+ $DB->update_record('grade_categories', $grade_category);
}
}
- if (isset($grade_category->parent)) {
- unset($grade_category->parent);
- }
$rs->close();
+ // Now we can rebuild all the paths
$rs = $DB->get_recordset('grade_categories', $conditions);
- if (!empty($rs)) {
- //now we can rebuild all the paths
- foreach($rs as $gc) {
- $grade_category->id = $gc->id;
- $grade_category->path = grade_category::build_path($gc);
- $DB->update_record('grade_categories', $grade_category);
- }
+ foreach ($rs as $gc) {
+ $grade_category = new stdClass();
+ $grade_category->id = $gc->id;
+ $grade_category->path = grade_category::build_path($gc);
+ $grade_category->depth = substr_count($grade_category->path, '/') - 1;
+ $DB->update_record('grade_categories', $grade_category);
}
$rs->close();
- //Restore marks items as needing update. Update everything now.
+ // Restore marks items as needing update. Update everything now.
grade_regrade_final_grades($this->get_courseid());
}
}

0 comments on commit a3b0c94

Please sign in to comment.