Skip to:
Content

BuddyPress.org

Changeset 11583


Ignore:
Timestamp:
06/09/2017 08:35:52 PM (8 years ago)
Author:
r-a-y
Message:

Activity: Fix activity comment deletion when comment ID equals 0.

In #7394, non-existent activity ID lookups now default to zero, instead of
the ID that was passed. For example, $a = new BP_Activity_Activity( 99 ),
$a->id now equals 0 instead of 99.

This is logistically correct; however, this raised a bug with
bp_activity_delete_comment() when passing 0 as the comment ID, which
could potentially delete all activity comments in the database.

Props Maniou.

Fixes #7450 (trunk)

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/bp-activity-functions.php

    r11447 r11583  
    29642964    }
    29652965
     2966    // Check if comment still exists.
     2967    $comment = new BP_Activity_Activity( $comment_id );
     2968    if ( empty( $comment->id ) ) {
     2969        return false;
     2970    }
     2971
    29662972    // Delete any children of this comment.
    29672973    bp_activity_delete_children( $activity_id, $comment_id );
     
    30043010     */
    30053011    function bp_activity_delete_children( $activity_id, $comment_id ) {
     3012        // Check if comment still exists.
     3013        $comment = new BP_Activity_Activity( $comment_id );
     3014        if ( empty( $comment->id ) ) {
     3015            return;
     3016        }
    30063017
    30073018        // Get activity children to delete.
  • trunk/tests/phpunit/testcases/activity/functions.php

    r10545 r11583  
    12791279
    12801280    /**
     1281     * @group  bp_activity_delete_comment
     1282     * @ticket BP7450
     1283     */
     1284    public function test_bp_activity_delete_comment_shouldnt_delete_all_comments_when_parameters_are_empty() {
     1285        $u = $this->factory->user->create();
     1286
     1287        // create an activity update
     1288        $parent_activity = $this->factory->activity->create( array(
     1289            'type'    => 'activity_update',
     1290            'user_id' => $u
     1291        ) );
     1292
     1293        // create some activity comments
     1294        $comment_one = bp_activity_new_comment( array(
     1295            'user_id'     => $u,
     1296            'activity_id' => $parent_activity,
     1297            'content'     => 'depth 1'
     1298        ) );
     1299
     1300        $comment_one_one = bp_activity_new_comment( array(
     1301            'user_id'     => $u,
     1302            'activity_id' => $parent_activity,
     1303            'parent_id'   => $comment_one,
     1304            'content'     => 'depth 2'
     1305        ) );
     1306
     1307        $comment_two = bp_activity_new_comment( array(
     1308            'user_id'     => $u,
     1309            'activity_id' => $parent_activity,
     1310            'content'     => 'depth 1'
     1311        ) );
     1312
     1313        // Pass empty values to bp_activity_delete_comment()
     1314        $retval = bp_activity_delete_comment( 0, 0 );
     1315        $this->assertFalse( $retval );
     1316
     1317        // Instantiate activity loop, which also includes activity comments.
     1318        bp_has_activities( 'display_comments=stream' );
     1319
     1320        // Activity comments should not be deleted.
     1321        $this->assertSame( 4, $GLOBALS['activities_template']->activity_count );
     1322
     1323        // Clean up after ourselves!
     1324        $GLOBALS['activities_template'] = null;
     1325    }
     1326
     1327    /**
    12811328     * @group bp_activity_new_comment
    12821329     * @group BP5907
Note: See TracChangeset for help on using the changeset viewer.