mirror of
https://github.com/moodle/moodle.git
synced 2025-01-30 03:58:34 +01:00
MDL-41417 course: allow the use of duplicated idnumbers if they existed before fix
This commit is contained in:
parent
5536a5617c
commit
c3bf6181aa
@ -329,7 +329,7 @@ class course_edit_form extends moodleform {
|
||||
|
||||
/// perform some extra moodle validation
|
||||
function validation($data, $files) {
|
||||
global $DB, $CFG;
|
||||
global $DB;
|
||||
|
||||
$errors = parent::validation($data, $files);
|
||||
|
||||
@ -341,10 +341,10 @@ class course_edit_form extends moodleform {
|
||||
}
|
||||
|
||||
// Add field validation check for duplicate idnumber.
|
||||
if (!empty($data['idnumber'])) {
|
||||
if (!empty($data['idnumber']) && (empty($data['id']) || $this->course->idnumber != $data['idnumber'])) {
|
||||
if ($course = $DB->get_record('course', array('idnumber' => $data['idnumber']), '*', IGNORE_MULTIPLE)) {
|
||||
if (empty($data['id']) || $course->id != $data['id']) {
|
||||
$errors['idnumber']= get_string('courseidnumbertaken', 'error', $course->fullname);
|
||||
$errors['idnumber'] = get_string('courseidnumbertaken', 'error', $course->fullname);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2382,7 +2382,6 @@ function update_course($data, $editoroptions = NULL) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!isset($data->category) or empty($data->category)) {
|
||||
// prevent nulls and 0 in category field
|
||||
unset($data->category);
|
||||
|
@ -660,7 +660,8 @@ class core_course_courselib_testcase extends advanced_testcase {
|
||||
global $DB;
|
||||
|
||||
$this->resetAfterTest();
|
||||
$defaultcategory = $DB->get_field_select('course_categories', "MIN(id)", "parent=0");
|
||||
|
||||
$defaultcategory = $DB->get_field_select('course_categories', 'MIN(id)', 'parent = 0');
|
||||
|
||||
$course = new stdClass();
|
||||
$course->fullname = 'Apu loves Unit Təsts';
|
||||
@ -672,11 +673,10 @@ class core_course_courselib_testcase extends advanced_testcase {
|
||||
$course->newsitems = 0;
|
||||
$course->numsections = 5;
|
||||
$course->category = $defaultcategory;
|
||||
$original = (array) $course;
|
||||
|
||||
$created = create_course($course);
|
||||
// Ensure the checks only work on idnumber/shortname that are not already ours.
|
||||
$created = update_course($created);
|
||||
update_course($created);
|
||||
|
||||
$course->shortname = 'test2';
|
||||
$course->idnumber = '2';
|
||||
@ -695,7 +695,6 @@ class core_course_courselib_testcase extends advanced_testcase {
|
||||
// Test duplicate shortname.
|
||||
$created2->idnumber = '2';
|
||||
$created2->shortname = 'test1';
|
||||
|
||||
try {
|
||||
update_course($created2);
|
||||
$this->fail('Expected exception when trying to update a course with a duplicate shortname');
|
||||
|
Loading…
x
Reference in New Issue
Block a user