Permalink
Browse files

Merge branch 'MDL-31314_21' of git://github.com/timhunt/moodle into M…

…OODLE_21_STABLE
  • Loading branch information...
2 parents 49b52b3 + 5fedb63 commit 7769c0f2f8a8581e0d15bcadec6b405e3ee0ebc5 @stronk7 stronk7 committed Jan 31, 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 7769c0f

Please sign in to comment.