Skip to:
Content

BuddyPress.org

Changeset 9377


Ignore:
Timestamp:
01/19/2015 08:49:46 PM (9 years ago)
Author:
johnjamesjacoby
Message:

Harden BP_Activity_Activity::rebuild_activity_comment_tree() by using intval() on recursively returned values, and use wp_list_pluck() to avoid touching object id directly. Also remove $bp global touch. See #5138.

File:
1 edited

Legend:

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

    r9376 r9377  
    13801380     * @since BuddyPress (1.2)
    13811381     *
    1382      * @global BuddyPress $bp The one true BuddyPress instance.
    1383      * @global wpdb $wpdb WordPress database object.
    1384      *
    1385      * @param int $parent_id ID of an activity or activity comment.
    1386      * @param int $left Node boundary start for activity or activity comment.
    1387      * @return int Right node boundary of activity or activity comment.
     1382     * @global wpdb $wpdb WordPress database object
     1383     *
     1384     * @param  int $parent_id ID of an activity or activity comment
     1385     * @param  int $left      Node boundary start for activity or activity comment
     1386     * @return int Right      Node boundary of activity or activity comment
    13881387     */
    13891388    public static function rebuild_activity_comment_tree( $parent_id, $left = 1 ) {
    1390         global $wpdb, $bp;
     1389        global $wpdb;
     1390
     1391        $bp = buddypress();
    13911392
    13921393        // The right value of this node is the left value + 1
    1393         $right = $left + 1;
     1394        $right = intval( $left + 1 );
    13941395
    13951396        // Get all descendants of this node
    1396         $descendants = BP_Activity_Activity::get_child_comments( $parent_id );
     1397        $comments    = BP_Activity_Activity::get_child_comments( $parent_id );
     1398        $descendants = wp_list_pluck( $comments, 'id' );
    13971399
    13981400        // Loop the descendants and recalculate the left and right values
    1399         foreach ( (array) $descendants as $descendant )
    1400             $right = BP_Activity_Activity::rebuild_activity_comment_tree( $descendant->id, $right );
     1401        foreach ( (array) $descendants as $descendant_id ) {
     1402            $right = BP_Activity_Activity::rebuild_activity_comment_tree( $descendant_id, $right );
     1403        }
    14011404
    14021405        // We've got the left value, and now that we've processed the children
    14031406        // of this node we also know the right value
    1404         if ( 1 == $left )
     1407        if ( 1 === $left ) {
    14051408            $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET mptt_left = %d, mptt_right = %d WHERE id = %d", $left, $right, $parent_id ) );
    1406         else
     1409        } else {
    14071410            $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET mptt_left = %d, mptt_right = %d WHERE type = 'activity_comment' AND id = %d", $left, $right, $parent_id ) );
     1411        }
    14081412
    14091413        // Return the right value of this node + 1
    1410         return $right + 1;
     1414        return intval( $right + 1 );
    14111415    }
    14121416
Note: See TracChangeset for help on using the changeset viewer.