aboutsummaryrefslogtreecommitdiff
path: root/mod/messages
diff options
context:
space:
mode:
authorcash <cash.costello@gmail.com>2013-03-30 12:32:00 -0400
committercash <cash.costello@gmail.com>2013-03-30 12:32:00 -0400
commit52a1bf6fd37021cb6bd1843898571ba2036fbf9d (patch)
tree448b1983c72736efd71f024dd8fb6884be2bb2ac /mod/messages
parentbc2bc90bd5282d08ed87dc374f4135d8182c931b (diff)
downloadelgg-52a1bf6fd37021cb6bd1843898571ba2036fbf9d.tar.gz
elgg-52a1bf6fd37021cb6bd1843898571ba2036fbf9d.tar.bz2
Fixes #5083 removes messages sent by deleted user
Diffstat (limited to 'mod/messages')
-rw-r--r--mod/messages/start.php32
1 files changed, 32 insertions, 0 deletions
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.