Permalink
Browse files

Merge branch 'wip-mdl-42556' of https://github.com/rajeshtaneja/moodle

  • Loading branch information...
danpoltawski committed Oct 29, 2013
2 parents b0d92c0 + abedc1a commit e29dcc5a5b69ab2670c83e2ab8af72dfdca2f4bf
Showing with 51 additions and 9 deletions.
  1. +33 −7 lib/classes/event/user_deleted.php
  2. +11 −2 lib/moodlelib.php
  3. +7 −0 lib/tests/moodlelib_test.php
@@ -58,7 +58,7 @@ public static function get_name() {
* @return string
*/
public function get_description() {
$user = (object)$this->other['user'];
$user = $this->get_record_snapshot('user', $this->data['objectid']);
return 'User profile deleted for user '.$user->firstname.' '.$user->lastname.' id ('.$user->id.')';
}
@@ -77,7 +77,13 @@ public static function get_legacy_eventname() {
* @return \stdClass user data.
*/
protected function get_legacy_eventdata() {
return (object)$this->other['user'];
$user = $this->get_record_snapshot('user', $this->data['objectid']);
$user->deleted = 0;
$user->username = $this->data['other']['username'];
$user->email = $this->data['other']['email'];
$user->idnumber = $this->data['other']['idnumber'];
$user->picture = $this->data['other']['picture'];
return $user;
}
/**
@@ -86,8 +92,8 @@ protected function get_legacy_eventdata() {
* @return array
*/
protected function get_legacy_logdata() {
$user = (object)$this->other['user'];
return array(SITEID, 'user', 'delete', "view.php?id=$user->id", $user->firstname.' '.$user->lastname);
$user = $this->get_record_snapshot('user', $this->data['objectid']);
return array(SITEID, 'user', 'delete', "view.php?id=".$user->id, $user->firstname.' '.$user->lastname);
}
/**
@@ -97,9 +103,29 @@ protected function get_legacy_logdata() {
* @return void
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->other['user'])) {
throw new \coding_exception('user must be set in $other.');
global $CFG;
if ($CFG->debugdeveloper) {
parent::validate_data();
if (!isset($this->other['username'])) {
throw new \coding_exception('username must be set in $other.');
}
if (!isset($this->other['email'])) {
throw new \coding_exception('email must be set in $other.');
}
if (!isset($this->other['idnumber'])) {
throw new \coding_exception('idnumber must be set in $other.');
}
if (!isset($this->other['picture'])) {
throw new \coding_exception('picture must be set in $other.');
}
if (!isset($this->other['mnethostid'])) {
throw new \coding_exception('mnethostid must be set in $other.');
}
}
}
}
View
@@ -4131,6 +4131,9 @@ function delete_user(stdClass $user) {
return false;
}
// Keep user record before updating it, as we have to pass this to user_deleted event.
$olduser = clone $user;
// Keep a copy of user context, we need it for event.
$usercontext = context_user::instance($user->id);
@@ -4210,10 +4213,16 @@ function delete_user(stdClass $user) {
array(
'objectid' => $user->id,
'context' => $usercontext,
'other' => array('user' => (array)clone $user)
'other' => array(
'username' => $user->username,
'email' => $user->email,
'idnumber' => $user->idnumber,
'picture' => $user->picture,
'mnethostid' => $user->mnethostid
)
)
);
$event->add_record_snapshot('user', $updateuser);
$event->add_record_snapshot('user', $olduser);
$event->trigger();
// We will update the user's timemodified, as it will be passed to the user_deleted event, which
@@ -1882,6 +1882,13 @@ public function test_delete_user() {
$this->assertEventLegacyData($user, $event);
$expectedlogdata = array(SITEID, 'user', 'delete', "view.php?id=$user->id", $user->firstname.' '.$user->lastname);
$this->assertEventLegacyLogData($expectedlogdata, $event);
$eventdata = $event->get_data();
$this->assertSame($eventdata['other']['username'], $user->username);
$this->assertSame($eventdata['other']['email'], $user->email);
$this->assertSame($eventdata['other']['idnumber'], $user->idnumber);
$this->assertSame($eventdata['other']['picture'], $user->picture);
$this->assertSame($eventdata['other']['mnethostid'], $user->mnethostid);
$this->assertEquals($user, $event->get_record_snapshot('user', $event->objectid));
// Try invalid params.
$record = new stdClass();

0 comments on commit e29dcc5

Please sign in to comment.