Changeset 7422
- Timestamp:
- 10/13/2013 02:36:04 AM (13 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
-
bp-activity/bp-activity-classes.php (modified) (4 diffs)
-
tests/testcases/activity/functions.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-activity/bp-activity-classes.php
r7403 r7422 551 551 * Otherwise use the filters. 552 552 * 553 * @since BuddyPress (1.2) 554 * 553 555 * @param array $args { 554 556 * @int $id Optional. The ID of a specific item to delete. … … 628 630 $activity_ids = $wpdb->get_col( "SELECT id FROM {$bp->activity->table_name} {$where_sql}" ); 629 631 630 if ( ! $wpdb->query( "DELETE FROM {$bp->activity->table_name} {$where_sql}" ) )632 if ( ! $wpdb->query( "DELETE FROM {$bp->activity->table_name} {$where_sql}" ) ) { 631 633 return false; 632 634 } 635 636 // Handle accompanying activity comments and meta deletion 633 637 if ( $activity_ids ) { 634 BP_Activity_Activity::delete_activity_item_comments( $activity_ids ); 638 $activity_ids_comma = implode( ',', wp_parse_id_list( $activity_ids ) ); 639 $activity_comments_where_sql = "WHERE type = 'activity_comment' AND item_id IN ({$activity_ids_comma})"; 640 641 // Fetch the activity comment IDs for our deleted activity items 642 $activity_comment_ids = $wpdb->get_col( "SELECT id FROM {$bp->activity->table_name} {$activity_comments_where_sql}" ); 643 644 // We have activity comments! 645 if ( ! empty( $activity_comment_ids ) ) { 646 // Delete activity comments 647 $wpdb->query( "DELETE FROM {$bp->activity->table_name} {$activity_comments_where_sql}" ); 648 649 // Merge activity IDs with activity comment IDs 650 $activity_ids = array_merge( $activity_ids, $activity_comment_ids ); 651 } 652 653 // Delete all activity meta entries for activity items and activity comments 635 654 BP_Activity_Activity::delete_activity_meta_entries( $activity_ids ); 636 637 return $activity_ids;638 655 } 639 656 … … 644 661 * Delete the comments associated with a set of activity items. 645 662 * 663 * @since BuddyPress (1.2) 664 * 665 * @todo Mark as deprecated? Method is no longer used internally. 666 * 646 667 * @param array $activity_ids Activity IDs whose comments should be deleted. 668 * @param bool $delete_meta Should we delete the activity meta items for these comments? 647 669 * @return bool True on success. 648 670 */ 649 public static function delete_activity_item_comments( $activity_ids = array() ) {671 public static function delete_activity_item_comments( $activity_ids = array(), $delete_meta = true ) { 650 672 global $bp, $wpdb; 651 673 674 $delete_meta = (bool) $delete_meta; 675 652 676 $activity_ids = implode( ',', wp_parse_id_list( $activity_ids ) ); 653 677 678 if ( $delete_meta ) { 679 // Fetch the activity comment IDs for our deleted activity items 680 $activity_comment_ids = $wpdb->get_col( "SELECT id FROM {$bp->activity->table_name} WHERE type = 'activity_comment' AND item_id IN ({$activity_ids})" ); 681 682 if ( ! empty( $activity_comment_ids ) ) { 683 self::delete_activity_meta_entries( $activity_comment_ids ); 684 } 685 } 686 654 687 return $wpdb->query( "DELETE FROM {$bp->activity->table_name} WHERE type = 'activity_comment' AND item_id IN ({$activity_ids})" ); 655 688 } … … 657 690 /** 658 691 * Delete the meta entries associated with a set of activity items. 692 * 693 * @since BuddyPress (1.2) 659 694 * 660 695 * @param array $activity_ids Activity IDs whose meta should be deleted. -
trunk/tests/testcases/activity/functions.php
r7039 r7422 35 35 } 36 36 37 /** 38 * @group delete 39 */ 40 public function test_delete_activity_and_meta() { 41 // create an activity update 42 $parent_activity = $this->factory->activity->create( array( 43 'type' => 'activity_update', 44 ) ); 45 46 // create some activity comments 47 $comment_one = $this->factory->activity->create( array( 48 'type' => 'activity_comment', 49 'item_id' => $parent_activity, 50 'secondary_item_id' => $parent_activity, 51 ) ); 52 53 $comment_two = $this->factory->activity->create( array( 54 'type' => 'activity_comment', 55 'item_id' => $parent_activity, 56 'secondary_item_id' => $parent_activity, 57 ) ); 58 59 // add some meta to the activity items 60 bp_activity_update_meta( $parent_activity, 'foo', 'bar' ); 61 bp_activity_update_meta( $comment_one, 'foo', 'bar' ); 62 bp_activity_update_meta( $comment_two, 'foo', 'bar' ); 63 64 // now delete the parent activity item 65 // this should hopefully delete the associated comments and meta entries 66 bp_activity_delete( array( 67 'id' => $parent_activity 68 ) ); 69 70 // now fetch the deleted activity entries 71 $get = bp_activity_get( array( 72 'in' => array( $parent_activity, $comment_one, $comment_two ), 73 'display_comments' => 'stream' 74 ) ); 75 76 // activities should equal zero 77 $this->assertEquals( 0, $get['total'] ); 78 79 // now fetch activity meta for the deleted activity entries 80 $m1 = bp_activity_get_meta( $parent_activity ); 81 $m2 = bp_activity_get_meta( $comment_one ); 82 $m3 = bp_activity_get_meta( $comment_two ); 83 84 // test if activity meta entries still exist 85 $this->assertEquals( false, $m1 ); 86 $this->assertEquals( false, $m2 ); 87 $this->assertEquals( false, $m3 ); 88 } 37 89 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)