MDL-42449 backup: Fix for activity grade category

Retain grade category when restoring an activity into the course that
it came from
This commit is contained in:
Andrew Hancox 2015-04-02 13:03:37 +01:00
parent 1d3fd63f97
commit baba473b24

View File

@ -3051,11 +3051,6 @@ class restore_activity_grades_structure_step extends restore_structure_step {
$oldparentid = $data->categoryid;
$courseid = $this->get_courseid();
// make sure top course category exists, all grade items will be associated
// to it. Later, if restoring the whole gradebook, categories will be introduced
$coursecat = grade_category::fetch_course_category($courseid);
$coursecatid = $coursecat->id; // Get the categoryid to be used
$idnumber = null;
if (!empty($data->idnumber)) {
// Don't get any idnumber from course module. Keep them as they are in grade_item->idnumber
@ -3080,8 +3075,18 @@ class restore_activity_grades_structure_step extends restore_structure_step {
}
}
if (!empty($data->categoryid)) {
// If the grade category id of the grade item being restored belongs to this course
// then it is a fair assumption that this is the correct grade category for the activity
// and we should leave it in place, if not then unset it.
// TODO MDL-34790 Gradebook does not import if target course has gradebook categories.
$conditions = array('id' => $data->categoryid, 'courseid' => $courseid);
if (!$this->task->is_samesite() || !$DB->record_exists('grade_categories', $conditions)) {
unset($data->categoryid);
}
}
unset($data->id);
$data->categoryid = $coursecatid;
$data->courseid = $this->get_courseid();
$data->iteminstance = $this->task->get_activityid();
$data->idnumber = $idnumber;