diff --git a/enrol/ldap/lang/en/enrol_ldap.php b/enrol/ldap/lang/en/enrol_ldap.php index f6ec711cd36..4d850327ca4 100644 --- a/enrol/ldap/lang/en/enrol_ldap.php +++ b/enrol/ldap/lang/en/enrol_ldap.php @@ -53,6 +53,7 @@ $string['course_summary_key'] = 'Summary'; $string['createcourseextid'] = 'CREATE User enrolled to a nonexistant course \'{$a->courseextid}\''; $string['createnotcourseextid'] = 'User enrolled to a nonexistant course \'{$a->courseextid}\''; $string['creatingcourse'] = 'Creating course \'{$a}\'...'; +$string['duplicateshortname'] = "Course creation failed. Duplicate short name. Skipping course with idnumber '{\$a->idnumber}'..."; $string['editlock'] = 'Lock value'; $string['emptyenrolment'] = "Empty enrolment for role '{\$a->role_shortname}' in course '{\$a->course_shortname}'\n"; $string['enrolname'] = 'LDAP'; diff --git a/enrol/ldap/lib.php b/enrol/ldap/lib.php index 9ebacb8be24..73eb118bdd3 100644 --- a/enrol/ldap/lib.php +++ b/enrol/ldap/lib.php @@ -990,6 +990,12 @@ class enrol_ldap_plugin extends enrol_plugin { $course->summary = $course_ext[$this->get_config('course_summary')][0]; } + // Check if the shortname already exists if it does - skip course creation. + if ($DB->record_exists('course', array('shortname' => $course->shortname))) { + $trace->output(get_string('duplicateshortname', 'enrol_ldap', $course)); + return false; + } + $newcourse = create_course($course); return $newcourse->id; }