MDL-40043 Events API: Added user_loggedinas event to replace add_to_log

This commit is contained in:
Rajesh Taneja
2013-08-20 14:07:35 +08:00
parent ed29bf0f66
commit 71298fea03
5 changed files with 200 additions and 14 deletions
+19 -3
View File
@@ -1163,11 +1163,13 @@ function session_get_realuser() {
* @return void
*/
function session_loginas($userid, $context) {
global $USER;
if (session_is_loggedinas()) {
return;
}
// switch to fresh new $SESSION
// Switch to fresh new $SESSION.
$_SESSION['REALSESSION'] = $_SESSION['SESSION'];
$_SESSION['SESSION'] = new stdClass();
@@ -1177,10 +1179,24 @@ function session_loginas($userid, $context) {
$user->realuser = $_SESSION['REALUSER']->id;
$user->loginascontext = $context;
// let enrol plugins deal with new enrolments if necessary
// Let enrol plugins deal with new enrolments if necessary.
enrol_check_plugins($user);
// set up global $USER
// Create event before $USER is updated.
$event = \core\event\user_loggedinas::create(
array(
'objectid' => $USER->id,
'context' => $context,
'relateduserid' => $userid,
'other' => array(
'originalusername' => fullname($USER, true),
'loggedinasusername' => fullname($user, true)
)
)
);
// Set up global $USER.
session_set_user($user);
$event->trigger();
}
/**