Skip to content

Commit

Permalink
MDL-37312 backup: Keep course idnumber on same site course restore
Browse files Browse the repository at this point in the history
When the course idnumber is set during a same site course restore,
retain the course idnumber if there are no duplicates.
  • Loading branch information
zbdd committed Aug 29, 2014
1 parent 1446e02 commit 7d908d3
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions backup/moodle2/restore_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1472,11 +1472,14 @@ public function process_course($data) {
$data->fullname = $fullname;
$data->shortname= $shortname;

// Only allow the idnumber to be set if the user has permission and the idnumber is not already in use by
// another course on this site.
$context = context::instance_by_id($this->task->get_contextid());
if (has_capability('moodle/course:changeidnumber', $context, $this->task->get_userid())) {
$data->idnumber = '';
if (!empty($data->idnumber) && has_capability('moodle/course:changeidnumber', $context, $this->task->get_userid()) &&
$this->task->is_samesite() && !$DB->record_exists('course', array('idnumber' => $data->idnumber))) {
// Do not reset idnumber.
} else {
unset($data->idnumber);
$data->idnumber = '';
}

// Any empty value for course->hiddensections will lead to 0 (default, show collapsed).
Expand Down

0 comments on commit 7d908d3

Please sign in to comment.