From 52a1bf6fd37021cb6bd1843898571ba2036fbf9d Mon Sep 17 00:00:00 2001 From: cash Date: Sat, 30 Mar 2013 12:32:00 -0400 Subject: Fixes #5083 removes messages sent by deleted user --- mod/messages/start.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'mod/messages') diff --git a/mod/messages/start.php b/mod/messages/start.php index 5503a675a..714129e4b 100644 --- a/mod/messages/start.php +++ b/mod/messages/start.php @@ -51,6 +51,9 @@ function messages_init() { elgg_register_plugin_hook_handler('notify:entity:message', 'object', 'messages_notification_msg'); register_notification_object('object', 'messages', elgg_echo('messages:new')); + // delete messages sent by a user when user is deleted + elgg_register_event_handler('delete', 'user', 'messages_purge'); + // ecml elgg_register_plugin_hook_handler('get_views', 'ecml', 'messages_ecml_views_hook'); @@ -425,6 +428,35 @@ function messages_user_hover_menu($hook, $type, $return, $params) { return $return; } +/** + * Delete messages from a user who is being deleted + * + * @param string $event Event name + * @param string $type Event type + * @param ElggUser $user User being deleted + */ +function messages_purge($event, $type, $user) { + + // make sure we delete them all + $entity_disable_override = access_get_show_hidden_status(); + access_show_hidden_entities(true); + $ia = elgg_set_ignore_access(true); + + $options = array( + 'type' => 'object', + 'subtype' => 'messages', + 'metadata_name' => 'fromId', + 'metadata_value' => $user->getGUID(), + 'limit' => 0, + ); + $batch = new ElggBatch('elgg_get_entities_from_metadata', $options); + foreach ($batch as $e) { + $e->delete(); + } + + elgg_set_ignore_access($ia); + access_show_hidden_entities($entity_disable_override); +} /** * Register messages with ECML. -- cgit v1.2.3 From 9a50f1530843f7fe8505b3424afcd40ad9e87900 Mon Sep 17 00:00:00 2001 From: cash Date: Sat, 30 Mar 2013 12:35:32 -0400 Subject: put test in to prevent deleting messages from everyone in case no guid - should never happen --- mod/messages/start.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'mod/messages') diff --git a/mod/messages/start.php b/mod/messages/start.php index 714129e4b..6d0e82744 100644 --- a/mod/messages/start.php +++ b/mod/messages/start.php @@ -437,6 +437,10 @@ function messages_user_hover_menu($hook, $type, $return, $params) { */ function messages_purge($event, $type, $user) { + if (!$user->getGUID()) { + return; + } + // make sure we delete them all $entity_disable_override = access_get_show_hidden_status(); access_show_hidden_entities(true); -- cgit v1.2.3