From d3080510e40c95b817b615b748557e127f5ec2cc Mon Sep 17 00:00:00 2001 From: peterbulmer Date: Mon, 18 May 2009 02:38:02 +0000 Subject: [PATCH] MDL19219 mnet, mitigate arrkey loss in transit 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 | 16 ++++++++++++++-- enrol/mnet/enrol.php | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/admin/mnet/enr_course_enrol.php b/admin/mnet/enr_course_enrol.php index c1e8664c2c..98b4f4926c 100644 --- a/admin/mnet/enr_course_enrol.php +++ b/admin/mnet/enr_course_enrol.php @@ -84,9 +84,21 @@ $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(); diff --git a/enrol/mnet/enrol.php b/enrol/mnet/enrol.php index d58dbfa926..95154196a7 100644 --- a/enrol/mnet/enrol.php +++ b/enrol/mnet/enrol.php @@ -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; -- 2.39.5