Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
10/13/2013 02:36:04 AM (13 years ago)
Author:
r-a-y
Message:

Delete activity comment meta when deleting parent activity items.

Previously, when deleting parent activity items, BP would delete the
related activity comments, but not the activity comment metadata.

To solve this, activity comments are now queried and removed in the
main BP_Activity_Activity::delete() method and the activity comment
IDs are now properly passed to the delete_activity_meta_entries()
method.

Commit also includes a unit test for this issue.

Hat-tip boonebgorges for feedback.

Fixes #5097.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/testcases/activity/functions.php

    r7039 r7422  
    3535        }
    3636
     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        }
    3789}
Note: See TracChangeset for help on using the changeset viewer.