]> git.mjollnir.org Git - moodle.git/commitdiff
MDL19219 mnet, mitigate arrkey loss in transit
authorpeterbulmer <peterbulmer>
Mon, 18 May 2009 02:38:02 +0000 (02:38 +0000)
committerpeterbulmer <peterbulmer>
Mon, 18 May 2009 02:38:02 +0000 (02:38 +0000)
When usernames are numeric, they are lost in mnet transit when used as
keys in the array result of course_enrolments(). As the username is not
sent with the enrolment details, it was not previously recoverable.
This patch adds the information to the enrolment details,
(enrol/mnet/enrol.php), and adds support for recovering the username if
it was numeric (and hence lost) (admin/mnet/enr_course_enrol.php)

admin/mnet/enr_course_enrol.php
enrol/mnet/enrol.php

index c1e8664c2c7d313dbe383eaaa97ebcd4f7b2b16f..98b4f4926c5bb20d740469cae6bffa252a952afd 100644 (file)
     $mnet_request->set_method('enrol/mnet/enrol.php/course_enrolments');
     $mnet_request->add_param($course->remoteid, 'int');
     $mnet_request->send($mnet_peer);
-    $all_enrolled_users = $mnet_request->response;
-
+    $raw_all_enrolled_users = $mnet_request->response;
     unset($mnet_request);
+
+    $all_enrolled_users = array();
+    if (!empty($raw_all_enrolled_users)) {
+        // Try to repair keying of remote users array, numeric usernames get lost in the fracas
+        foreach ($raw_all_enrolled_users as $username => $userdetails) {
+            if (empty($userdetails['username']) || !is_numeric($username)) {
+                //Not able to repair, or no need to repair
+                $all_enrolled_users[$username] = $userdetails;
+            } else {
+                $all_enrolled_users[$userdetails['username']] = $userdetails;
+            }
+        }
+    }
     
     $all_enrolled_usernames = '';
     $timemodified = array();
index d58dbfa9260d0741fac5e9b59ab313dcf8f2f9ee..95154196a74e3328444278cea2469c6e267a73b1 100644 (file)
@@ -281,6 +281,7 @@ class enrolment_plugin_mnet {
             $returnarray[$user->username] = array('enrol' => $user->enrol, 
                                                   'timemodified' => $user->timemodified, 
                                                   'shortname' => $user->shortname, 
+                                                  'username' => $user->username,
                                                   'name' => $user->name);
         }
         return $returnarray;