Commit 582c19e2 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Delete users' data when deleting users (bug 3103)

parent 9225e143
......@@ -417,6 +417,11 @@ class ArtefactTypeEmail extends ArtefactTypeProfileField {
}
}
}
public function delete() {
delete_records('artefact_internal_profile_email', 'artefact', $this->id);
parent::delete();
}
}
class ArtefactTypeStudentid extends ArtefactTypeProfileField {}
......
......@@ -316,6 +316,14 @@ class ArtefactTypePersonalinformation extends ArtefactTypeResume {
return array('html' => $smarty->fetch('artefact:resume:fragments/personalinformation.tpl'));
}
public function delete() {
db_begin();
delete_records('artefact_resume_personal_information', 'artefact', $this->id);
parent::delete();
db_commit();
}
}
......
......@@ -125,8 +125,10 @@ if ($groups['data']) {
WHERE m1.group = m2.group AND m2.member < m1.member
)
AND m1.group IN (" . implode($groupids, ',') . ')', array());
foreach ($members as $m) {
$groups['data'][$m->group]->members[] = (object) array('id' => $m->id, 'name' => display_name($m));
if ($members) {
foreach ($members as $m) {
$groups['data'][$m->group]->members[] = (object) array('id' => $m->id, 'name' => display_name($m));
}
}
}
$groups['data'] = array_values($groups['data']);
......
......@@ -347,6 +347,11 @@ class InteractionForumInstance extends InteractionInstance {
public function interaction_remove_user($userid) {
delete_records('interaction_forum_moderator', 'forum', $this->id, 'user', $userid);
delete_records('interaction_forum_subscription_forum', 'forum', $this->id, 'user', $userid);
delete_records_select('interaction_forum_subscription_topic',
'user = ? AND topic IN (SELECT id FROM {interaction_forum_topic} WHERE forum = ?)',
array($userid, $this->id)
);
}
}
......
......@@ -402,9 +402,9 @@ function group_user_can_leave($group, $userid=null) {
* @param int $groupid ID of group
* @param int $userid ID of user to remove
*/
function group_remove_user($groupid, $userid=null) {
function group_remove_user($groupid, $userid=null, $force=false) {
// group_user_can_leave checks the validity of groupid and userid
if (!group_user_can_leave($groupid, $userid)) {
if (!$force && !group_user_can_leave($groupid, $userid)) {
throw new AccessDeniedException(get_string('usercantleavegroup', 'group'));
}
db_begin();
......@@ -663,10 +663,13 @@ function group_prepare_usergroups_for_display($groups, $returnto='mygroups') {
$groupadmins = array();
$groupids = array_map(create_function('$a', 'return $a->id;'), $groups);
if ($groupids) {
$groupadmins = (array)get_records_sql_array('SELECT "group", member
$groupadmins = get_records_sql_array('SELECT "group", member
FROM {group_member}
WHERE "group" IN (' . implode(',', db_array_to_ph($groupids)) . ")
AND role = 'admin'", $groupids);
if (!$groupadmins) {
$groupadmins = array();
}
}
$i = 0;
......
......@@ -764,15 +764,14 @@ function delete_user($userid) {
update_record('usr', $deleterec);
// Because the user is being deleted, but their email address may be wanted
// for a new user, we change their email addresses to add
// 'deleted.[timestamp]'
execute_sql('UPDATE {artefact_internal_profile_email}
SET email = email || ?
WHERE owner = ?', array($datasuffix, $userid));
// Remove user from any groups they're in, invited to or want to be in
delete_records('group_member', 'member', $userid);
$groupids = get_column('group_member', '"group"', 'member', $userid);
if ($groupids) {
require_once(get_config('libroot') . 'group.php');
foreach ($groupids as $groupid) {
group_remove_user($groupid, $userid, true);
}
}
delete_records('group_member_request', 'member', $userid);
delete_records('group_member_invite', 'member', $userid);
......@@ -784,8 +783,39 @@ function delete_user($userid) {
WHERE owner = ?
OR requester = ?', array($userid, $userid));
// Remove remote user records
delete_records('artefact_access_usr', 'usr', $userid);
delete_records('auth_remote_user', 'localusr', $userid);
delete_records('import_queue', 'usr', $userid);
delete_records('usr_account_preference', 'usr', $userid);
delete_records('usr_activity_preference', 'usr', $userid);
delete_records('usr_infectedupload', 'usr', $userid);
delete_records('usr_institution', 'usr', $userid);
delete_records('usr_institution_request', 'usr', $userid);
delete_records('usr_password_request', 'usr', $userid);
delete_records('usr_watchlist_view', 'usr', $userid);
delete_records('view_access_usr', 'usr', $userid);
// Remove the user's views & artefacts
$viewids = get_column('view', 'id', 'owner', $userid);
if ($viewids) {
require_once(get_config('libroot') . 'view.php');
foreach ($viewids as $viewid) {
$view = new View($viewid);
$view->delete();
}
}
$artefactids = get_column('artefact', 'id', 'owner', $userid);
if ($artefactids) {
foreach ($artefactids as $artefactid) {
try {
$a = artefact_instance_from_id($artefactid);
$a->delete();
}
catch (ArtefactNotFoundException $e) {
// Awesome, it's already gone.
}
}
}
db_commit();
......
......@@ -119,6 +119,22 @@ class PluginNotificationEmaildigest extends PluginNotification {
}
}
}
public static function get_event_subscriptions() {
$subscriptions = array(
(object)array(
'plugin' => 'emaildigest',
'event' => 'deleteuser',
'callfunction' => 'deleteuser',
),
);
return $subscriptions;
}
public static function deleteuser($event, $user) {
delete_records('notification_emaildigest_queue', 'usr', $user['id']);
}
}
?>
......@@ -27,7 +27,7 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2007041300;
$config->release = '0.2';
$config->version = 2009012700;
$config->release = '1.0.1';
?>
......@@ -57,6 +57,21 @@ class PluginNotificationInternal extends PluginNotification {
return count_records('notification_internal_activity', 'usr', $userid, 'read', 0);
}
public static function get_event_subscriptions() {
$subscriptions = array(
(object)array(
'plugin' => 'internal',
'event' => 'deleteuser',
'callfunction' => 'deleteuser',
),
);
return $subscriptions;
}
public static function deleteuser($event, $user) {
delete_records('notification_internal_activity', 'usr', $user['id']);
}
}
?>
......@@ -27,7 +27,7 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2006102700;
$config->release = '0.1';
$config->version = 2009012700;
$config->release = '1.0.1';
?>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment