aboutsummaryrefslogtreecommitdiff
path: root/mod/messages
diff options
context:
space:
mode:
authorSteve Clay <steve@mrclay.org>2013-03-31 15:40:44 -0700
committerSteve Clay <steve@mrclay.org>2013-03-31 15:40:44 -0700
commit835c7fe5eb77343081b9bd33ec465f9ce8929570 (patch)
treea1f30ac6b545ef93538a677386c36ead614bfb34 /mod/messages
parent9bbefd18fb86beff8766334459646bcb6d145d28 (diff)
parent9a50f1530843f7fe8505b3424afcd40ad9e87900 (diff)
downloadelgg-835c7fe5eb77343081b9bd33ec465f9ce8929570.tar.gz
elgg-835c7fe5eb77343081b9bd33ec465f9ce8929570.tar.bz2
Merge pull request #5300 from cash/remove_private_messages
Fixes #5083: Remove private messages sent by deleted user
Diffstat (limited to 'mod/messages')
-rw-r--r--mod/messages/start.php36
1 files changed, 36 insertions, 0 deletions
diff --git a/mod/messages/start.php b/mod/messages/start.php
index 5503a675a..6d0e82744 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,39 @@ 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) {
+
+ if (!$user->getGUID()) {
+ return;
+ }
+
+ // 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.