[buddypress-trac] [BuddyPress] #5097: Activity meta data not deleted for the comments of an activity when the activity is deleted (bloating the meta table with orphans)

buddypress-trac noreply at wordpress.org
Fri Jul 12 23:42:50 UTC 2013


#5097: Activity meta data not deleted for the comments of an activity when the
activity is deleted (bloating the meta table with orphans)
--------------------------+-----------------------------
 Reporter:  dtc7240       |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Core          |    Version:
 Severity:  normal        |   Keywords:  has-patch
--------------------------+-----------------------------
 Create an activity with a comment and a comment to the comment, making
 sure that some meta data exists for each (Askimet entries dutifully
 suffice).

 If you delete the first comment, the meta data for it and its child are
 correctly removed from the database, as ''bp_activity_delete_comment''
 recursively calls ''bp_activity_delete'' from the bottom comment up, one
 at a time.

 If however, you delete the activity itself, the meta data for both
 comments remain in the ''wp_bp_activity_meta'' table (and any custom table
 using the ''bp_activity_deleted_activities'' hook), '''bloating the meta
 table(s) with orphans'''.

 In this case, when ''bp_activity_delete'' calls
 ''BP_Activity_Activity::delete'', the value of ''$activity_ids'' only ever
 contains the id of the activity itself, instead of adding the ids of the
 child comments it found when calling
 ''BP_Activity_Activity::delete_activity_item_comments( $activity_ids )''.
 Thus, when it next calls
 ''BP_Activity_Activity::delete_activity_meta_entries( $activity_ids )'',
 only the meta data for the activity itself is removed.

 I suggest we change this existing function within ''class
 BP_Activity_Activity'':

 {{{
 function delete_activity_item_comments( $activity_ids = array() ) {
         global $bp, $wpdb;

         $activity_ids = implode( ',', wp_parse_id_list( $activity_ids ) );

         return $wpdb->query( "DELETE FROM {$bp->activity->table_name}
 WHERE type = 'activity_comment' AND item_id IN ({$activity_ids})" );
 }

 }}}

 to the following in order to add the comment ids to ''$activity_ids'':

 {{{
 function delete_activity_item_comments( &$activity_ids = array() ) {
         global $bp, $wpdb;

         $activity_id_list = implode( ',', wp_parse_id_list( $activity_ids
 ) );

         $activity_ids = array_merge( $activity_ids, $wpdb->get_col(
 "SELECT id FROM {$bp->activity->table_name} WHERE type =
 'activity_comment' AND item_id IN ({$activity_id_list})" ));

         return $wpdb->query( "DELETE FROM {$bp->activity->table_name}
 WHERE type = 'activity_comment' AND item_id IN ({$activity_id_list})" );
 }

 }}}

 There may be a more efficient way to handle the DELETE in order to keep
 from running essentially the same query twice (that someone more
 experienced than me might implement).

 I've tested this fix in my own development application, and it works
 great.  Even for the custom meta table I've created to service both the
 activity and message tables with my own specific typing across both forms
 of communication ( utilizing the ''bp_activity_deleted_activities'' hook).

 Thank you,
 Scott Seitz

--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/5097>
BuddyPress <http://buddypress.org/>
BuddyPress


More information about the buddypress-trac mailing list