Skip to:
Content

bbPress.org

Opened 7 weeks ago

Last modified 3 weeks ago

#3637 assigned defect (bug)

Forum with subforums update the last topic incorrectly

Reported by: terresquall's profile terresquall Owned by: johnjamesjacoby's profile johnjamesjacoby
Milestone: 2.7 Priority: normal
Severity: major Version: 2.6.13
Component: Component - Forums Keywords: has-patch
Cc:

Description

When a forum only has subforums, it will always consider only the last subforum when selecting the latest topic. This is because the bbp_update_forum_last_topic_id() function does not properly find and update the $children_last_topic when looping through all subforums:

Loop through children and add together forum reply counts
$children = bbp_forum_query_subforum_ids( $forum_id );
if ( ! empty( $children ) ) {

foreach ( $children as $child ) {

$children_last_topic = bbp_update_forum_last_topic_id( $child ); Recursive

}

}

$children_last_topic will always find the latest topic ID of the final subforum, when in actuality, it should also be comparing the last topic of all forums and picking the latest one of all of them:

Loop through children and add together forum reply counts
$children = bbp_forum_query_subforum_ids( $forum_id );
if ( ! empty( $children ) ) {


We want to record the last active time.
$latest_last_active = PHP_INT_MIN;


foreach ( $children as $child ) {

$child_last_topic = bbp_update_forum_last_topic_id( $child ); Recursive.


If the response is invalid.
if(!empty($child_last_topic)) {

We need to get the last active time, because we need to compare them.
$child_last_active = bbp_get_topic_last_active_time($child_last_topic);


Update the last topic only if it is later.
if($child_last_active > $latest_last_active) {

$latest_last_active = $child_last_active;
$children_last_topic = $child_last_topic;

}

}

}

}

Attachments (1)

fix.patch (1.2 KB) - added by terresquall 7 weeks ago.
Patch file for the fix.

Download all attachments as: .zip

Change History (3)

#1 @terresquall
7 weeks ago

The code didn't render properly. This is where the problem is (first block of code):

<?php
                // Loop through children and add together forum reply counts
                $children = bbp_forum_query_subforum_ids( $forum_id );
                if ( ! empty( $children ) ) {
                        foreach ( $children as $child ) {
                                $children_last_topic = bbp_update_forum_last_topic_id( $child ); // Recursive
                        }
                }

And this is the edited one:

<?php
                // Loop through children and add together forum reply counts
                $children = bbp_forum_query_subforum_ids( $forum_id );
                if ( ! empty( $children ) ) {
                        
                        // We want to record the last active time.
                        $latest_last_active = PHP_INT_MIN;
                        
                        foreach ( $children as $child ) {
                                $child_last_topic = bbp_update_forum_last_topic_id( $child ); // Recursive.
                                
                                // If the response is invalid.
                                if(!empty($child_last_topic)) {
                                        // We need to get the last active time, because we need to compare them.
                                        $child_last_active = bbp_get_topic_last_active_time($child_last_topic);
                                        
                                        // Update the last topic only if it is later.
                                        if($child_last_active > $latest_last_active) {
                                                $latest_last_active = $child_last_active;
                                                $children_last_topic = $child_last_topic;
                                        }
                                }
                        }
                }

@terresquall
7 weeks ago

Patch file for the fix.

#2 @johnjamesjacoby
3 weeks ago

  • Keywords has-patch added
  • Milestone changed from Awaiting Review to 2.7
  • Owner set to johnjamesjacoby
Note: See TracTickets for help on using tickets.