Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit fc7837532377e217de56ac98cc2f5a0d658a93c4 1 parent 93dc135
peterbulmer authored
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
@@ -85,9 +85,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;
Please sign in to comment.
Something went wrong with that request. Please try again.