Skip to content

Commit

Permalink
MDL-31314 gradebook restore: fix category.depth on restore.
Browse files Browse the repository at this point in the history
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
timhunt committed Jan 30, 2012
1 parent d4b3034 commit a3b0c94
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions backup/moodle2/restore_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down

0 comments on commit a3b0c94

Please sign in to comment.