Skip to:
Content

bbPress.org


Ignore:
Timestamp:
09/09/2011 09:43:33 PM (10 years ago)
Author:
johnjamesjacoby
Message:

Fix issue when topics and replies are flagged as spam/trash where they would still update last active data for ancestors. Fixes #1631.
Fix issue when trashing and deleting a topic, replies may not be properly queried and updated. Fixes #1629.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-includes/bbp-forum-functions.php

    r3445 r3501  
    387387    $forum_id = bbp_get_forum_id( $forum_id );
    388388
     389    // Define local variable(s)
     390    $children_last_topic = 0;
     391
    389392    // Do some calculation if not manually set
    390393    if ( empty( $topic_id ) ) {
    391394
    392395        // Loop through children and add together forum reply counts
    393         if ( $children = bbp_forum_query_subforum_ids( $forum_id ) )
    394             foreach ( (array) $children as $child )
    395                 $children_last_topic = bbp_update_forum_last_topic_id ( $child );
     396        if ( $children = bbp_forum_query_subforum_ids( $forum_id ) ) {
     397            foreach ( (array) $children as $child ) {
     398                $children_last_topic = bbp_update_forum_last_topic_id( $child ); // Recursive
     399            }
     400        }
    396401
    397402        // Setup recent topic query vars
     
    405410
    406411        // Get the most recent topic in this forum_id
    407         if ( $recent_topic = get_posts( $post_vars ) )
     412        if ( $recent_topic = get_posts( $post_vars ) ) {
    408413            $topic_id = $recent_topic[0]->ID;
    409     }
     414        }
     415    }
     416
     417    // Cast as integer in case of empty or string
     418    $topic_id            = (int) $topic_id;
     419    $children_last_topic = (int) $children_last_topic;
    410420
    411421    // If child forums have higher id, use that instead
     
    413423        $topic_id = $children_last_topic;
    414424
    415     // Update the last topic id
    416     update_post_meta( $forum_id, '_bbp_last_topic_id', (int) $topic_id );
    417 
    418     return apply_filters( 'bbp_update_forum_last_topic_id', (int) $topic_id, $forum_id );
     425    // Update the last public topic ID
     426    if ( bbp_is_topic_published( $topic_id ) )
     427        update_post_meta( $forum_id, '_bbp_last_topic_id', $topic_id );
     428
     429    return apply_filters( 'bbp_update_forum_last_topic_id', $topic_id, $forum_id );
    419430}
    420431
     
    432443 * @uses bbp_forum_query_topic_ids() To get the topic ids in the forum
    433444 * @uses bbp_forum_query_last_reply_id() To get the forum's last reply id
     445 * @uses bbp_is_reply_published() To make sure the reply is published
    434446 * @uses update_post_meta() To update the forum's last active id meta
    435447 * @uses apply_filters() Calls 'bbp_update_forum_last_reply_id' with the last
     
    440452    $forum_id = bbp_get_forum_id( $forum_id );
    441453
     454    // Define local variable(s)
     455    $children_last_reply = 0;
     456
    442457    // Do some calculation if not manually set
    443458    if ( empty( $reply_id ) ) {
    444459
    445460        // Loop through children and get the most recent reply id
    446         if ( $children = bbp_forum_query_subforum_ids( $forum_id ) )
    447             foreach ( (array) $children as $child )
    448                 $children_last_reply = bbp_update_forum_last_reply_id ( $child );
     461        if ( $children = bbp_forum_query_subforum_ids( $forum_id ) ) {
     462            foreach ( (array) $children as $child ) {
     463                $children_last_reply = bbp_update_forum_last_reply_id( $child ); // Recursive
     464            }
     465        }
    449466
    450467        // If this forum has topics...
     
    459476    }
    460477
     478    // Cast as integer in case of empty or string
     479    $reply_id            = (int) $reply_id;
     480    $children_last_reply = (int) $children_last_reply;
     481   
    461482    // If child forums have higher ID, check for newer reply id
    462     if ( !empty( $children ) && ( (int) $children_last_reply > (int) $reply_id ) )
     483    if ( !empty( $children ) && ( $children_last_reply > $reply_id ) )
    463484        $reply_id = $children_last_reply;
    464485
    465     // Update the last reply id with what was passed
    466     update_post_meta( $forum_id, '_bbp_last_reply_id', (int) $reply_id );
    467 
    468     return apply_filters( 'bbp_update_forum_last_reply_id', (int) $reply_id, $forum_id );
     486    // Update the last public reply ID
     487    if ( bbp_is_reply_published( $reply_id ) )
     488        update_post_meta( $forum_id, '_bbp_last_reply_id', $reply_id );
     489
     490    return apply_filters( 'bbp_update_forum_last_reply_id', $reply_id, $forum_id );
    469491}
    470492
     
    482504 * @uses bbp_forum_query_topic_ids() To get the topic ids in the forum
    483505 * @uses bbp_forum_query_last_reply_id() To get the forum's last reply id
     506 * @uses get_post_status() To make sure the reply is published
    484507 * @uses update_post_meta() To update the forum's last active id meta
    485508 * @uses apply_filters() Calls 'bbp_update_forum_last_active_id' with the last
     
    490513    $forum_id = bbp_get_forum_id( $forum_id );
    491514
     515    // Define local variable(s)
     516    $children_last_active = 0;
     517
    492518    // Do some calculation if not manually set
    493519    if ( empty( $active_id ) ) {
     
    509535    }
    510536
     537    // Cast as integer in case of empty or string
     538    $active_id            = (int) $active_id;
     539    $children_last_active = (int) $children_last_active;
     540
    511541    // If child forums have higher id, use that instead
    512542    if ( !empty( $children ) && ( $children_last_active > $active_id ) )
    513543        $active_id = $children_last_active;
    514544
    515     update_post_meta( $forum_id, '_bbp_last_active_id', (int) $active_id );
     545    // Update only if published
     546    if ( 'publish' == get_post_status( $active_id ) )
     547        update_post_meta( $forum_id, '_bbp_last_active_id', (int) $active_id );
    516548
    517549    return apply_filters( 'bbp_update_forum_last_active_id', (int) $active_id, $forum_id );
     
    540572        $new_time = get_post_field( 'post_date', bbp_get_forum_last_active_id( $forum_id ) );
    541573
    542     update_post_meta( $forum_id, '_bbp_last_active_time', $new_time );
     574    // Update only if there is a time
     575    if ( !empty( $new_time ) )
     576        update_post_meta( $forum_id, '_bbp_last_active_time', $new_time );
    543577
    544578    return apply_filters( 'bbp_update_forum_last_active', $new_time, $forum_id );
     
    589623
    590624    // Loop through subforums and add together forum topic counts
    591     if ( $children = bbp_forum_query_subforum_ids( $forum_id ) )
    592         foreach ( (array) $children as $child )
    593             $children_topic_count += bbp_update_forum_topic_count( $child );
     625    if ( $children = bbp_forum_query_subforum_ids( $forum_id ) ) {
     626        foreach ( (array) $children as $child ) {
     627            $children_topic_count += bbp_update_forum_topic_count( $child ); // Recursive
     628        }
     629    }
    594630
    595631    // Get total topics for this forum
     
    726762function bbp_update_forum( $args = '' ) {
    727763    $defaults = array(
    728         'forum_id'         => 0,
    729         'post_parent'      => 0,
    730         'last_topic_id'    => 0,
    731         'last_reply_id'    => 0,
    732         'last_active_id'   => 0,
    733         'last_active_time' => 0,
     764        'forum_id'           => 0,
     765        'post_parent'        => 0,
     766        'last_topic_id'      => 0,
     767        'last_reply_id'      => 0,
     768        'last_active_id'     => 0,
     769        'last_active_time'   => 0,
     770        'last_active_status' => 'publish'
    734771    );
    735772
     
    748785        $last_active_time = get_post_field( 'post_date', $last_active_id );
    749786
    750     bbp_update_forum_last_active_time( $forum_id, $last_active_time );
     787    if ( 'publish' == $last_active_status ) {
     788        bbp_update_forum_last_active_time( $forum_id, $last_active_time );
     789    }
    751790
    752791    // Counts
Note: See TracChangeset for help on using the changeset viewer.