Skip to content

Commit

Permalink
MDL-41417 course: allow the use of duplicated idnumbers if they exist…
Browse files Browse the repository at this point in the history
…ed before fix
  • Loading branch information
mdjnelson committed Sep 6, 2013
1 parent 5536a56 commit c3bf618
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
6 changes: 3 additions & 3 deletions course/edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ function definition_after_data() {

/// perform some extra moodle validation
function validation($data, $files) {
global $DB, $CFG;
global $DB;

$errors = parent::validation($data, $files);

Expand All @@ -341,10 +341,10 @@ function validation($data, $files) {
}

// 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);
}
}
}
Expand Down
1 change: 0 additions & 1 deletion course/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 3 additions & 4 deletions course/tests/courselib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,8 @@ public function test_update_course() {
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';
Expand All @@ -672,11 +673,10 @@ public function test_update_course() {
$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';
Expand All @@ -695,7 +695,6 @@ public function test_update_course() {
// 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');
Expand Down

0 comments on commit c3bf618

Please sign in to comment.