From: danmarsden Date: Mon, 24 Jul 2006 00:37:58 +0000 (+0000) Subject: Bug #5882 ldap enrolment doesn't work. $USER->student getting munged X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=f2b7abf058f0d180e2c66b51dede4d854011377d;p=moodle.git Bug #5882 ldap enrolment doesn't work. $USER->student getting munged patch from IƱaki. --- diff --git a/enrol/ldap/enrol.php b/enrol/ldap/enrol.php index 93bc7115d9..6fbfc4033e 100755 --- a/enrol/ldap/enrol.php +++ b/enrol/ldap/enrol.php @@ -81,6 +81,9 @@ function get_user_courses(&$user, $type) { } } + /// Add it to new list + $newenrolments[$course_obj->id] = 'ldap'; + // deal with enrolment in the moodle db if (!empty($course_obj)) { // does course exist now? if(isset($user->{$type}[$course_obj->id]) && $user->{$type}[$course_obj->id] == 'ldap'){ @@ -105,18 +108,26 @@ function get_user_courses(&$user, $type) { // array, those are old enrolments that we want to remove (or are they?) if(!empty($user->{$type})){ foreach ($user->{$type} as $courseid => $value){ - if($value == 'ldap'){ // this was a legacy + if($value === 'ldap'){ // this was a legacy if ($type === 'student') { // enrol unenrol_student($user->id, $courseid); } else if ($type === 'teacher') { remove_teacher($user->id, $courseid); } unset($user->{$type}[$course_obj->id]); + } else { + // This one is from a non-database + // enrolment. Add it to the newenrolments + // array, so we don't loose it. + $newenrolments[$courseid] = $value; } } } + /// Overwrite the old array with the new one + $user->{$type} = $newenrolments; + @ldap_close($ldap_connection); return true; }