Changeset 9377
- Timestamp:
- 01/19/2015 08:49:46 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-activity/bp-activity-classes.php
r9376 r9377 1380 1380 * @since BuddyPress (1.2) 1381 1381 * 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 1388 1387 */ 1389 1388 public static function rebuild_activity_comment_tree( $parent_id, $left = 1 ) { 1390 global $wpdb, $bp; 1389 global $wpdb; 1390 1391 $bp = buddypress(); 1391 1392 1392 1393 // The right value of this node is the left value + 1 1393 $right = $left + 1;1394 $right = intval( $left + 1 ); 1394 1395 1395 1396 // 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' ); 1397 1399 1398 1400 // 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 } 1401 1404 1402 1405 // We've got the left value, and now that we've processed the children 1403 1406 // of this node we also know the right value 1404 if ( 1 == $left )1407 if ( 1 === $left ) { 1405 1408 $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET mptt_left = %d, mptt_right = %d WHERE id = %d", $left, $right, $parent_id ) ); 1406 else1409 } else { 1407 1410 $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 } 1408 1412 1409 1413 // Return the right value of this node + 1 1410 return $right + 1;1414 return intval( $right + 1 ); 1411 1415 } 1412 1416
Note: See TracChangeset
for help on using the changeset viewer.