diff --git a/backup/moodle2/restore_stepslib.php b/backup/moodle2/restore_stepslib.php index c9705a98b33..6486489b96c 100644 --- a/backup/moodle2/restore_stepslib.php +++ b/backup/moodle2/restore_stepslib.php @@ -1109,7 +1109,6 @@ class restore_course_structure_step extends restore_structure_step { global $CFG, $DB; $data = (object)$data; - $oldid = $data->id; // We'll need this later $fullname = $this->get_setting_value('course_fullname'); $shortname = $this->get_setting_value('course_shortname'); @@ -1122,7 +1121,13 @@ class restore_course_structure_step extends restore_structure_step { $data->id = $this->get_courseid(); $data->fullname = $fullname; $data->shortname= $shortname; - $data->idnumber = ''; + + $context = get_context_instance_by_id($this->task->get_contextid()); + if (has_capability('moodle/course:changeidnumber', $context, $this->task->get_userid())) { + $data->idnumber = ''; + } else { + unset($data->idnumber); + } // Only restrict modules if original course was and target site too for new courses $data->restrictmodules = $data->restrictmodules && !empty($CFG->restrictmodulesfor) && $CFG->restrictmodulesfor == 'all';