]> git.mjollnir.org Git - moodle.git/commitdiff
Bug #5882 ldap enrolment doesn't work. $USER->student getting munged
authordanmarsden <danmarsden>
Mon, 24 Jul 2006 00:37:58 +0000 (00:37 +0000)
committerdanmarsden <danmarsden>
Mon, 24 Jul 2006 00:37:58 +0000 (00:37 +0000)
patch from IƱaki.

enrol/ldap/enrol.php

index 93bc7115d93a2b8c3a07fd49a80cd902ef864aee..6fbfc4033ecce820f5fb76d1328107884cad43cf 100755 (executable)
@@ -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;
 }