From 7d7d82de038f0e9606eb20b8006130995c99730c Mon Sep 17 00:00:00 2001 From: Andrew Robert Nicols Date: Fri, 30 Sep 2011 14:54:24 +0100 Subject: [PATCH] MDL-29591 Check for permission before overwriting course idnumber when restoring --- backup/moodle2/restore_stepslib.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/backup/moodle2/restore_stepslib.php b/backup/moodle2/restore_stepslib.php index 3044c7ff808..6fd5fc8d59c 100644 --- a/backup/moodle2/restore_stepslib.php +++ b/backup/moodle2/restore_stepslib.php @@ -1102,7 +1102,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'); @@ -1115,7 +1114,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';