Browse files

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)
  • Loading branch information...
1 parent a56e6b5 commit d813bd8763beaa2d6f5e2a424028f77658627fd1 peterbulmer committed May 18, 2009
Showing with 15 additions and 2 deletions.
  1. +14 −2 admin/mnet/enr_course_enrol.php
  2. +1 −0 enrol/mnet/enrol.php
View
16 admin/mnet/enr_course_enrol.php
@@ -86,9 +86,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;
+ }
+ }
+ }
$select = '';
$all_enrolled_usernames = '';
View
1 enrol/mnet/enrol.php
@@ -287,6 +287,7 @@ function course_enrolments($courseid, $roles = '') {
$returnarray[$user->username] = array('enrol' => $user->enrol,
'timemodified' => $user->timemodified,
'shortname' => $user->shortname,
+ 'username' => $user->username,
'name' => $user->name);
}
return $returnarray;

0 comments on commit d813bd8

Please sign in to comment.