Permalink
Browse files

MDL-32178 ignore duplicates in enroL_database external course table

  • Loading branch information...
1 parent 8d716ac commit 3a48019ea3ba039bd234247e522280d549cb5065 @skodak skodak committed with Sam Hemelryk May 6, 2012
Showing with 13 additions and 0 deletions.
  1. +13 −0 enrol/database/lib.php
View
13 enrol/database/lib.php
@@ -689,6 +689,19 @@ public function sync_courses($verbose = false) {
$newcourse->idnumber = $fields->idnumber;
$newcourse->category = $fields->category ? $fields->category : $defaultcategory;
+ // Detect duplicate data once again, above we can not find duplicates
+ // in external data using DB collation rules...
+ if ($DB->record_exists('course', array('shortname' => $newcourse->shortname))) {
+ if ($verbose) {
+ mtrace(" can not insert new course, duplicate shortname detected: ".$newcourse->shortname);
+ }
+ continue;
+ } else if (!empty($newcourse->idnumber) and $DB->record_exists('course', array('idnumber' => $newcourse->idnumber))) {
+ if ($verbose) {
+ mtrace(" can not insert new course, duplicate idnumber detected: ".$newcourse->idnumber);
+ }
+ continue;
+ }
$c = create_course($newcourse);
if ($verbose) {
mtrace(" creating course: $c->id, $c->fullname, $c->shortname, $c->idnumber, $c->category");

0 comments on commit 3a48019

Please sign in to comment.