Skip to:
Content

BuddyPress.org

Changeset 6410


Ignore:
Timestamp:
10/15/2012 07:09:43 PM (14 years ago)
Author:
boonebgorges
Message:

Ensure that BP_Activity_Activity::get() pulls up comments for non-top-level items

There was previously an exception in BP_Activity_Activity::append_comments()
that would make it impossible to load activity comments for activity items
that were themselves activity comments. This changeset removes the restriction,
and adds the necessary top_level_parent_id parameter to the get_comments()
method so that the comment tree is pulled up correctly in all cases.

Fixes #4600

Props sboisvert

File:
1 edited

Legend:

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

    r6342 r6410  
    453453                $activity_comments = array();
    454454
    455                 /* Now fetch the activity comments and parse them into the correct position in the activities array. */
     455                // Now fetch the activity comments and parse them into the correct position in the activities array.
    456456                foreach( (array) $activities as $activity ) {
    457                         if ( 'activity_comment' != $activity->type && $activity->mptt_left && $activity->mptt_right )
    458                                 $activity_comments[$activity->id] = BP_Activity_Activity::get_activity_comments( $activity->id, $activity->mptt_left, $activity->mptt_right, $spam );
    459                 }
    460 
    461                 /* Merge the comments with the activity items */
     457                        $top_level_parent_id = 'activity_comment' == $activity->type ? $activity->item_id : 0;
     458                        $activity_comments[$activity->id] = BP_Activity_Activity::get_activity_comments( $activity->id, $activity->mptt_left, $activity->mptt_right, $spam );
     459                }
     460
     461                // Merge the comments with the activity items
    462462                foreach( (array) $activities as $key => $activity )
    463463                        if ( isset( $activity_comments[$activity->id] ) )
     
    476476         * @param into $right Right-most node boundary
    477477         * @param bool $spam Optional; 'ham_only' (default), 'spam_only' or 'all'.
     478         * @param int $top_level_parent_id The id of the root-level parent activity item
    478479         * @return array The updated activities with nested comments
    479480         * @since BuddyPress (1.2)
    480481         */
    481         function get_activity_comments( $activity_id, $left, $right, $spam = 'ham_only' ) {
    482                 global $wpdb, $bp;
     482        function get_activity_comments( $activity_id, $left, $right, $spam = 'ham_only', $top_level_parent_id = 0 ) {
     483                global $wpdb, $bp;
     484
     485                if ( empty( $top_level_parent_id ) ) {
     486                        $top_level_parent_id = $activity_id;
     487                }
    483488
    484489                if ( !$comments = wp_cache_get( 'bp_activity_comments_' . $activity_id ) ) {
     
    502507                                $spam_sql = '';
    503508
    504                         $sql = apply_filters( 'bp_activity_comments_user_join_filter', $wpdb->prepare( "SELECT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name{$fullname_select} FROM {$bp->activity->table_name} a, {$wpdb->users} u{$fullname_from} WHERE u.ID = a.user_id {$fullname_where} AND a.type = 'activity_comment' ${spam_sql} AND a.item_id = %d AND a.mptt_left BETWEEN %d AND %d ORDER BY a.date_recorded ASC", $activity_id, $left, $right ), $activity_id, $left, $right, $spam_sql );
     509                        // The mptt BETWEEN clause allows us to limit returned descendants to the right part of the tree
     510                        $sql = apply_filters( 'bp_activity_comments_user_join_filter', $wpdb->prepare( "SELECT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name{$fullname_select} FROM {$bp->activity->table_name} a, {$wpdb->users} u{$fullname_from} WHERE u.ID = a.user_id {$fullname_where} AND a.type = 'activity_comment' ${spam_sql} AND a.item_id = %d AND a.mptt_left BETWEEN %d AND %d ORDER BY a.date_recorded ASC", $top_level_parent_id, $left, $right ), $activity_id, $left, $right, $spam_sql );
    505511
    506512                        // Retrieve all descendants of the $root node
Note: See TracChangeset for help on using the changeset viewer.