mirror of
https://github.com/moodle/moodle.git
synced 2025-08-08 02:16:41 +02:00
MDL-41417 course: prevent duplicate idnumbers being used when updating a course
This commit is contained in:
parent
b69ec2889e
commit
5536a5617c
4 changed files with 77 additions and 16 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue