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)
This commit is contained in:
@@ -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 = '';
|
||||
|
||||
@@ -287,6 +287,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;
|
||||
|
||||
Reference in New Issue
Block a user