MDL-41417 course: prevent duplicate idnumbers being used when updating a course

This commit is contained in:
Francis Devine 2013-09-04 21:21:41 +12:00 committed by Mark Nelson
parent b69ec2889e
commit 5536a5617c
4 changed files with 77 additions and 16 deletions

View file

@ -2368,6 +2368,21 @@ function update_course($data, $editoroptions = NULL) {
$data = file_postupdate_standard_filemanager($data, 'overviewfiles', $overviewfilesoptions, $context, 'course', 'overviewfiles', 0);
}
// Check we don't have a duplicate shortname.
if (!empty($data->shortname) && $oldcourse->shortname != $data->shortname) {
if ($DB->record_exists('course', array('shortname' => $data->shortname))) {
throw new moodle_exception('shortnametaken', '', '', $data->shortname);
}
}
// Check we don't have a duplicate idnumber.
if (!empty($data->idnumber) && $oldcourse->idnumber != $data->idnumber) {
if ($DB->record_exists('course', array('idnumber' => $data->idnumber))) {
throw new moodle_exception('courseidnumbertaken', '', '', $data->idnumber);
}
}
if (!isset($data->category) or empty($data->category)) {
// prevent nulls and 0 in category field
unset($data->category);