Skip to:
Content

BuddyPress.org

Changeset 9961


Ignore:
Timestamp:
06/22/2015 07:17:05 PM (9 years ago)
Author:
r-a-y
Message:

Activity: When calculating the activity comment depth, prevent an infinite loop when the parent activity item is not an activity update.

In #2768, we added the ability to calculate the activity comment depth.
The code at the time was meant to calculate the activity comment depth for
regular activity updates ('activity_update'). However, it is possible
for other activity types to have activity comments attached to them. For
example, since the introduction of comment syncing in 2.0, it is now
possible for activity comments to be attached to 'new_blog_post' items.

When fetching activity comments attached to other activity types (as in the
case when using the "New Comments" activity dropdown filter), an infinite
loop can occur while traversing up the activity tree to calculate the
activity comment depth.

This commit fixes this by checking if the parent activity item is not an
activity update during activity comment depth calculation. If the parent
activity is not an activity update, we have reached the top of the tree can
bail from the recursive depth check.

Fixes #6518.

File:
1 edited

Legend:

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

    r9834 r9961  
    14151415                $depth = 1;
    14161416                $parent_id = $r->secondary_item_id;
     1417
    14171418                while ( $parent_id !== $r->item_id ) {
    14181419                    $depth++;
    14191420
    1420                     // When display_comments=stream, the
    1421                     // parent comment may not be part of
    1422                     // the returned results, so we manually
    1423                     // fetch it
     1421                    // When display_comments=stream, the parent comment may not be part of the
     1422                    // returned results, so we manually fetch it
    14241423                    if ( empty( $ref[ $parent_id ] ) ) {
    14251424                        $direct_parent = new BP_Activity_Activity( $parent_id );
    14261425                        if ( isset( $direct_parent->secondary_item_id ) ) {
    1427                             $parent_id = $direct_parent->secondary_item_id;
     1426                            // If the direct parent is not an activity update, that means we've reached
     1427                            // the parent activity item (eg. new_blog_post)
     1428                            if ( 'activity_update' !== $direct_parent->type ) {
     1429                                $parent_id = $r->item_id;
     1430
     1431                            } else {
     1432                                $parent_id = $direct_parent->secondary_item_id;
     1433                            }
     1434
    14281435                        } else {
    1429                             // Something went wrong
    1430                             // Short-circuit the
    1431                             // depth calculation
     1436                            // Something went wrong.  Short-circuit the depth calculation
    14321437                            $parent_id = $r->item_id;
    14331438                        }
Note: See TracChangeset for help on using the changeset viewer.