Skip to:
Content

Changeset 9184


Ignore:
Timestamp:
11/26/2014 06:08:39 AM (4 years ago)
Author:
r-a-y
Message:

Grab all message IDs before deleting a message thread.

In BP_Messages_Thread::delete(), we need to grab all message IDs before
a message thread is outright deleted. This is done by using
$wpdb->get_col() instead of $wpdb->get_var().

This commit also:

  • Deletes the message meta attached to the message (see #3083)
  • Reinstates the 'messages_thread_deleted_hook' action that was improperly removed in r9165
  • Adds $message_ids as an extra parameter to the 'bp_messages_thread_after_delete' action
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-messages/bp-messages-classes.php

    r9183 r9184  
    255255        $wpdb->query( $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET is_deleted = 1 WHERE thread_id = %d AND user_id = %d", $thread_id, bp_loggedin_user_id() ) );
    256256
    257         // Get the message id in order to pass to the action
    258         $message_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_messages} WHERE thread_id = %d", $thread_id ) );
     257        // Get the message ids in order to pass to the action
     258        $message_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_messages} WHERE thread_id = %d", $thread_id ) );
    259259
    260260        // Check to see if any more recipients remain for this message
     
    266266            $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->messages->table_name_messages} WHERE thread_id = %d", $thread_id ) );
    267267
     268            // Do something for each message ID
     269            foreach ( $message_ids as $message_id ) {
     270                // Delete message meta
     271                bp_messages_delete_meta( $message_id );
     272
     273                /**
     274                 * Fires after a message is deleted. This hook is poorly named.
     275                 *
     276                 * @since BuddyPress (1.0.0)
     277                 *
     278                 * @param int $message_id ID of the message
     279                 */
     280                do_action( 'messages_thread_deleted_thread', $message_id );
     281            }
     282
    268283            // Delete all the recipients
    269284            $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->messages->table_name_recipients} WHERE thread_id = %d", $thread_id ) );
     
    271286
    272287        /**
    273          * Fires after a message thread is deleted.
     288         * Fires after a message thread is either marked as deleted or deleted
    274289         *
    275290         * @since BuddyPress (2.2.0)
    276291         *
    277          * @param int $thread_id ID of the thread being deleted.
     292         * @param int   $thread_id   ID of the thread being deleted.
     293         * @param array $message_ids IDs of messages being deleted.
    278294         */
    279         do_action( 'bp_messages_thread_after_delete', $message_id );
     295        do_action( 'bp_messages_thread_after_delete', $thread_id, $message_ids );
    280296
    281297        return true;
Note: See TracChangeset for help on using the changeset viewer.