Skip to:
Content

bbPress.org


Ignore:
Timestamp:
11/09/2019 05:35:42 AM (4 years ago)
Author:
johnjamesjacoby
Message:

Counts (meta-data): full audit of forum/topic/reply, public/non-public counts.

This commit is the result of a full count audit, exposing multiple inconsistencies and voids in relation to how public and non-public counts are (re)calculated.

For instance, hidden forum replies are not counted at all, until now. By introducing a new Repair tool, hidden forum reply counts are now counted.

In addition, there were multiple bugs with topic & reply moderation, where the act of approving or unapproving topics or replies would cause the numbers to be inaccurate, or where topics & replies being caught in moderation were still increasing public counts.

It was also possible to, as a Key Master, publicly reply to unapproved topics, which was a completely unanticipated side-effect of allowing Key Masters to do pretty much anything. Going forward, the default reply status is the topic status, but is still beholden to all existing moderation settings and user role capabilities. This results in a more sane user experience, and prevents the unusual circumstance of there being "0 topics and 30 replies" in public-facing forums.

Certain count increase/decrease actions have been reprioritized to avoid collisions and race conditions, proving once again that ya gotta get up to get down.

See #2838. Fixes #1799.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/admin/tools/repair.php

    r6908 r6923  
    263263
    264264/**
    265  * Recount topic hidden replies (spammed/trashed)
     265 * Recount non-public replies per topic (pending/spammed/trashed)
    266266 *
    267267 * @since 2.0.0 bbPress (r2747)
     
    405405        foreach ( $forums as $forum ) {
    406406            bbp_update_forum_reply_count( $forum->ID );
     407        }
     408    } else {
     409        return array( 2, sprintf( $statement, $result ) );
     410    }
     411
     412    return array( 0, sprintf( $statement, esc_html__( 'Complete!', 'bbpress' ) ) );
     413}
     414
     415/**
     416 * Recount non-public forum replies
     417 *
     418 * @since 2.6.0 bbPress (r6922)
     419 *
     420 * @return array An array of the status code and the message
     421 */
     422function bbp_admin_repair_forum_reply_count_hidden() {
     423
     424    // Define variables
     425    $bbp_db    = bbp_db();
     426    $statement = esc_html__( 'Counting the number of pending, spammed, and trashed replies in each forum… %s', 'bbpress' );
     427    $result    = esc_html__( 'Failed!', 'bbpress' );
     428
     429    // Post type
     430    $fpt = bbp_get_forum_post_type();
     431
     432    // Delete the meta keys _bbp_reply_count and _bbp_total_reply_count for each forum
     433    $sql_delete = "DELETE `postmeta` FROM `{$bbp_db->postmeta}` AS `postmeta`
     434                        LEFT JOIN `{$bbp_db->posts}` AS `posts` ON `posts`.`ID` = `postmeta`.`post_id`
     435                        WHERE `posts`.`post_type` = '{$fpt}'
     436                        AND `postmeta`.`meta_key` = '_bbp_reply_count_hidden'
     437                        OR `postmeta`.`meta_key` = '_bbp_total_reply_count_hidden'";
     438
     439    if ( is_wp_error( $bbp_db->query( $sql_delete ) ) ) {
     440        return array( 1, sprintf( $statement, $result ) );
     441    }
     442
     443    // Recalculate the metas key _bbp_reply_count and _bbp_total_reply_count for each forum
     444    $forums = get_posts( array( 'post_type' => bbp_get_forum_post_type(), 'numberposts' => -1 ) );
     445    if ( ! empty( $forums ) ) {
     446        foreach ( $forums as $forum ) {
     447            bbp_update_forum_reply_count_hidden( $forum->ID );
    407448        }
    408449    } else {
Note: See TracChangeset for help on using the changeset viewer.