MDL-29591 Check for permission before overwriting course idnumber when restoring
authorAndrew Robert Nicols <andrew.nicols@luns.net.uk>
Fri, 30 Sep 2011 13:54:24 +0000 (14:54 +0100)
committerAndrew Robert Nicols <andrew.nicols@luns.net.uk>
Fri, 18 Nov 2011 14:54:00 +0000 (14:54 +0000)
backup/moodle2/restore_stepslib.php

index 3044c7f..6fd5fc8 100644 (file)
@@ -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';