Skip to:
Content

bbPress.org

Changeset 6534


Ignore:
Timestamp:
06/12/2017 09:23:32 PM (8 years ago)
Author:
johnjamesjacoby
Message:

Engagements: Revert part of r6525, and adjust some actions.

  • Engagements will need to be "public only" for 2.6, and we can reconsider what private/hidden engagements look like later
  • Make sure that engagements are saved before voice counts are done
  • Use new is_public style wrapper function for topics & replies where appropriate
  • Remove a few current_filter() checks that should no longer be necessary with current action hook implementation
  • There may be more clean-up necessary here, but this is required to bring all unit-tests back to passing as they've been written, specifically things hooked to the bbp_insert_topic and bbp_insert_reply hooks

See #3068. Hat-tip netweb.

Location:
trunk/src/includes
Files:
6 edited

Legend:

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

    r6525 r6534  
    178178    $tpt = bbp_get_topic_post_type();
    179179    $rpt = bbp_get_reply_post_type();
     180    $pps = bbp_get_public_status_id();
     181    $cps = bbp_get_closed_status_id();
    180182    $sql = "INSERT INTO {$bbp_db->postmeta} (post_id, meta_key, meta_value) (
    181183            SELECT postmeta.meta_value, '_bbp_engagement', posts.post_author
     
    185187                    AND postmeta.meta_key = '_bbp_topic_id'
    186188                WHERE posts.post_type IN (%s, %s)
     189                    AND posts.post_status IN (%s, %s)
    187190                GROUP BY postmeta.meta_value, posts.post_author)";
    188191
    189192    // Run the big query
    190     $prepare     = $bbp_db->prepare( $sql, $tpt, $rpt );
     193    $prepare     = $bbp_db->prepare( $sql, $tpt, $rpt, $pps, $cps );
    191194    $engagements = $bbp_db->query( $prepare );
    192195
  • trunk/src/includes/core/actions.php

    r6530 r6534  
    258258add_action( 'bbp_trashed_reply',    'bbp_decrease_forum_reply_count'        );
    259259add_action( 'bbp_trashed_topic',    'bbp_decrease_forum_topic_count'        );
    260 add_action( 'bbp_trashed_topic',    'bbp_increase_forum_topic_count_hidden' );
    261260add_action( 'bbp_untrashed_reply',  'bbp_increase_forum_reply_count'        );
    262261add_action( 'bbp_untrashed_topic',  'bbp_increase_forum_topic_count'        );
    263 add_action( 'bbp_untrashed_topic',  'bbp_decrease_forum_topic_count_hidden' );
    264262add_action( 'bbp_spammed_reply',    'bbp_decrease_forum_reply_count'        );
    265263add_action( 'bbp_spammed_topic',    'bbp_decrease_forum_topic_count'        );
    266 add_action( 'bbp_spammed_topic',    'bbp_increase_forum_topic_count_hidden' );
    267264add_action( 'bbp_unspammed_reply',  'bbp_increase_forum_reply_count'        );
    268265add_action( 'bbp_unspammed_topic',  'bbp_increase_forum_topic_count'        );
    269 add_action( 'bbp_unspammed_topic',  'bbp_decrease_forum_topic_count_hidden' );
    270266add_action( 'bbp_approved_reply',   'bbp_increase_forum_reply_count'        );
    271267add_action( 'bbp_approved_topic',   'bbp_increase_forum_topic_count'        );
    272 add_action( 'bbp_approved_topic',   'bbp_decrease_forum_topic_count_hidden' );
    273268add_action( 'bbp_unapproved_reply', 'bbp_decrease_forum_reply_count'        );
    274269add_action( 'bbp_unapproved_topic', 'bbp_decrease_forum_topic_count'        );
     270add_action( 'bbp_trashed_topic',    'bbp_increase_forum_topic_count_hidden' );
     271add_action( 'bbp_untrashed_topic',  'bbp_decrease_forum_topic_count_hidden' );
     272add_action( 'bbp_spammed_topic',    'bbp_increase_forum_topic_count_hidden' );
     273add_action( 'bbp_unspammed_topic',  'bbp_decrease_forum_topic_count_hidden' );
     274add_action( 'bbp_approved_topic',   'bbp_decrease_forum_topic_count_hidden' );
    275275add_action( 'bbp_unapproved_topic', 'bbp_increase_forum_topic_count_hidden' );
    276276
     
    282282add_action( 'bbp_new_reply',        'bbp_increase_topic_reply_count'        );
    283283add_action( 'bbp_trashed_reply',    'bbp_decrease_topic_reply_count'        );
     284add_action( 'bbp_untrashed_reply',  'bbp_increase_topic_reply_count'        );
     285add_action( 'bbp_spammed_reply',    'bbp_decrease_topic_reply_count'        );
     286add_action( 'bbp_unspammed_reply',  'bbp_increase_topic_reply_count'        );
     287add_action( 'bbp_approved_reply',   'bbp_increase_topic_reply_count'        );
     288add_action( 'bbp_unapproved_reply', 'bbp_decrease_topic_reply_count'        );
    284289add_action( 'bbp_trashed_reply',    'bbp_increase_topic_reply_count_hidden' );
    285 add_action( 'bbp_untrashed_reply',  'bbp_increase_topic_reply_count'        );
    286290add_action( 'bbp_untrashed_reply',  'bbp_decrease_topic_reply_count_hidden' );
    287 add_action( 'bbp_spammed_reply',    'bbp_decrease_topic_reply_count'        );
    288291add_action( 'bbp_spammed_reply',    'bbp_increase_topic_reply_count_hidden' );
    289 add_action( 'bbp_unspammed_reply',  'bbp_increase_topic_reply_count'        );
    290292add_action( 'bbp_unspammed_reply',  'bbp_decrease_topic_reply_count_hidden' );
    291 add_action( 'bbp_approved_reply',   'bbp_increase_topic_reply_count'        );
    292293add_action( 'bbp_approved_reply',   'bbp_decrease_topic_reply_count_hidden' );
    293 add_action( 'bbp_unapproved_reply', 'bbp_decrease_topic_reply_count'        );
    294294add_action( 'bbp_unapproved_reply', 'bbp_increase_topic_reply_count_hidden' );
    295295add_action( 'bbp_deleted_reply',    'bbp_decrease_topic_reply_count_hidden' );
     
    307307add_action( 'bbp_spam_reply',    'bbp_decrease_user_reply_count' );
    308308
    309 // Insert topic/reply engagements.
    310 add_action( 'bbp_insert_topic', 'bbp_update_topic_engagements' );
    311 add_action( 'bbp_insert_reply', 'bbp_update_topic_engagements' );
    312 
    313 // Insert topic/reply counts.
    314 add_action( 'bbp_insert_topic', 'bbp_insert_topic_update_counts', 10, 2 );
    315 add_action( 'bbp_insert_reply', 'bbp_insert_reply_update_counts', 10, 3 );
    316 
    317 // Update engagements.
    318 add_action( 'bbp_new_topic', 'bbp_update_topic_engagements' );
    319 add_action( 'bbp_new_reply', 'bbp_update_topic_engagements' );
    320 
    321 // Recalculate engagements.
    322 add_action( 'bbp_deleted_topic', 'bbp_recalculate_topic_engagements' );
    323 add_action( 'bbp_deleted_reply', 'bbp_recalculate_topic_engagements' );
    324 
    325 // Update engagement counts.
    326 add_action( 'bbp_new_reply',        'bbp_update_topic_voice_count' );
    327 add_action( 'bbp_trashed_reply',    'bbp_update_topic_voice_count' );
    328 add_action( 'bbp_untrashed_reply',  'bbp_update_topic_voice_count' );
    329 add_action( 'bbp_spammed_reply',    'bbp_update_topic_voice_count' );
    330 add_action( 'bbp_unspammed_reply',  'bbp_update_topic_voice_count' );
    331 add_action( 'bbp_approved_reply',   'bbp_update_topic_voice_count' );
    332 add_action( 'bbp_unapproved_reply', 'bbp_update_topic_voice_count' );
    333 add_action( 'bbp_deleted_reply',    'bbp_update_topic_voice_count' );
    334 
    335 // Insert reply voice counts.
    336 add_action( 'bbp_insert_reply', 'bbp_update_topic_voice_count' );
    337 
    338309// Topic status transition helpers for replies
    339310add_action( 'bbp_trash_topic',   'bbp_trash_topic_replies'   );
     
    342313add_action( 'bbp_spam_topic',    'bbp_spam_topic_replies'    );
    343314add_action( 'bbp_unspam_topic',  'bbp_unspam_topic_replies'  );
     315
     316// Topic engagements on user creation.
     317add_action( 'bbp_new_topic', 'bbp_update_topic_engagements', 20 );
     318add_action( 'bbp_new_reply', 'bbp_update_topic_engagements', 20 );
     319
     320add_action( 'bbp_new_reply', 'bbp_update_topic_voice_count', 30 );
     321add_action( 'bbp_new_topic', 'bbp_update_topic_voice_count', 30 );
     322
     323// Topic/reply counts on code insert (unit tests)
     324add_action( 'bbp_insert_topic', 'bbp_insert_topic_update_counts', 10, 2 );
     325add_action( 'bbp_insert_reply', 'bbp_insert_reply_update_counts', 10, 3 );
     326
     327// Topic engagements on code insert (unit tests)
     328add_action( 'bbp_insert_topic', 'bbp_update_topic_engagements', 20 );
     329add_action( 'bbp_insert_reply', 'bbp_update_topic_engagements', 20 );
     330
     331// Topic engagement counts on code insert (unit tests)
     332add_action( 'bbp_insert_topic', 'bbp_update_topic_voice_count', 30 );
     333add_action( 'bbp_insert_reply', 'bbp_update_topic_voice_count', 30 );
     334
     335// Recalculate engagements.
     336add_action( 'bbp_trashed_reply',    'bbp_recalculate_topic_engagements' );
     337add_action( 'bbp_untrashed_reply',  'bbp_recalculate_topic_engagements' );
     338add_action( 'bbp_spammed_reply',    'bbp_recalculate_topic_engagements' );
     339add_action( 'bbp_unspammed_reply',  'bbp_recalculate_topic_engagements' );
     340add_action( 'bbp_approved_reply',   'bbp_recalculate_topic_engagements' );
     341add_action( 'bbp_unapproved_reply', 'bbp_recalculate_topic_engagements' );
     342add_action( 'bbp_deleted_reply',    'bbp_recalculate_topic_engagements' );
     343add_action( 'bbp_trashed_topic',    'bbp_recalculate_topic_engagements' );
     344add_action( 'bbp_untrashed_topic',  'bbp_recalculate_topic_engagements' );
     345add_action( 'bbp_spammed_topic',    'bbp_recalculate_topic_engagements' );
     346add_action( 'bbp_unspammed_topic',  'bbp_recalculate_topic_engagements' );
     347add_action( 'bbp_approved_topic',   'bbp_recalculate_topic_engagements' );
     348add_action( 'bbp_unapproved_topic', 'bbp_recalculate_topic_engagements' );
     349add_action( 'bbp_deleted_topic',    'bbp_recalculate_topic_engagements' );
     350
     351// Update engagement counts.
     352add_action( 'bbp_trashed_reply',    'bbp_update_topic_voice_count', 30 );
     353add_action( 'bbp_untrashed_reply',  'bbp_update_topic_voice_count', 30 );
     354add_action( 'bbp_spammed_reply',    'bbp_update_topic_voice_count', 30 );
     355add_action( 'bbp_unspammed_reply',  'bbp_update_topic_voice_count', 30 );
     356add_action( 'bbp_approved_reply',   'bbp_update_topic_voice_count', 30 );
     357add_action( 'bbp_unapproved_reply', 'bbp_update_topic_voice_count', 30 );
     358add_action( 'bbp_deleted_reply',    'bbp_update_topic_voice_count', 30 );
     359add_action( 'bbp_trashed_topic',    'bbp_update_topic_voice_count', 30 );
     360add_action( 'bbp_untrashed_topic',  'bbp_update_topic_voice_count', 30 );
     361add_action( 'bbp_spammed_topic',    'bbp_update_topic_voice_count', 30 );
     362add_action( 'bbp_unspammed_topic',  'bbp_update_topic_voice_count', 30 );
     363add_action( 'bbp_approved_topic',   'bbp_update_topic_voice_count', 30 );
     364add_action( 'bbp_unapproved_topic', 'bbp_update_topic_voice_count', 30 );
     365add_action( 'bbp_deleted_topic',    'bbp_update_topic_voice_count', 30 );
    344366
    345367// User status
  • trunk/src/includes/forums/functions.php

    r6529 r6534  
    12051205        $forum_id = bbp_get_topic_forum_id( $topic_id );
    12061206
    1207         // If this is a new, unpublished, topic, increase hidden count and bail.
    1208         if ( 'bbp_new_topic' === current_filter() && ( ! bbp_is_topic_published( $topic_id ) && ! bbp_is_topic_closed( $topic_id ) ) ) {
     1207        // Bail if not public.
     1208        if ( ! bbp_is_topic_public( $topic_id ) ) {
    12091209            bbp_increase_forum_topic_count_hidden( $forum_id );
    12101210            return;
     
    14191419    // If it's a reply, get the forum id.
    14201420    if ( bbp_is_reply( $forum_id ) ) {
    1421         $reply_id = $forum_id;
    1422         $forum_id = bbp_get_reply_forum_id( $reply_id );
    1423 
    1424         // Don't update if this is a new, unpublished, reply.
    1425         if ( 'bbp_new_reply' === current_filter() && ! bbp_is_reply_published( $reply_id ) ) {
    1426             return;
    1427         }
     1421        $forum_id = bbp_get_reply_forum_id( $forum_id );
    14281422    }
    14291423
  • trunk/src/includes/replies/functions.php

    r6529 r6534  
    109109
    110110    // If the reply is public, update the forum/topic reply counts.
    111     if ( bbp_get_reply_status( $reply_id ) === bbp_get_public_status_id() ) {
     111    if ( bbp_is_reply_published( $reply_id ) ) {
    112112        bbp_increase_topic_reply_count( $topic_id );
    113         bbp_increase_forum_reply_count( $forum_id );
     113        bbp_increase_forum_reply_count( $reply_id );
    114114
    115115    // If the reply isn't public only update the topic reply hidden count.
  • trunk/src/includes/topics/functions.php

    r6529 r6534  
    25182518
    25192519        // If this is a new, unpublished, reply, update hidden count and bail.
    2520         if ( 'bbp_new_reply' === current_filter() && ! bbp_is_reply_published( $reply_id ) ) {
     2520        if ( ! bbp_is_reply_published( $reply_id ) ) {
    25212521            bbp_increase_topic_reply_count_hidden( $topic_id );
    25222522            return;
     
    26642664
    26652665    // If the topic is public, update the forum topic counts.
    2666     if ( bbp_get_topic_status( $topic_id ) === bbp_get_public_status_id() ) {
     2666    if ( bbp_is_topic_public( $topic_id ) ) {
    26672667        bbp_increase_forum_topic_count( $forum_id );
    26682668
     
    26952695
    26962696    // If it's a reply, then get the parent (topic id)
    2697     if ( bbp_is_reply( $topic_id ) ) {
    2698         $topic_id = bbp_get_reply_topic_id( $topic_id );
    2699     } else {
    2700         $topic_id = bbp_get_topic_id( $topic_id );
    2701     }
    2702 
     2697    $topic_id = bbp_is_reply( $topic_id )
     2698        ? bbp_get_reply_topic_id( $topic_id )
     2699        : bbp_get_topic_id( $topic_id );
     2700
     2701    // Forum ID fallback
    27032702    if ( empty( $forum_id ) ) {
    27042703        $forum_id = get_post_field( 'post_parent', $topic_id );
     
    27532752
    27542753    // If it's a reply, then get the parent (topic id)
    2755     if ( bbp_is_reply( $topic_id ) ) {
    2756         $topic_id = bbp_get_reply_topic_id( $topic_id );
    2757     } else {
    2758         $topic_id = bbp_get_topic_id( $topic_id );
    2759     }
     2754    $topic_id = bbp_is_reply( $topic_id )
     2755        ? bbp_get_reply_topic_id( $topic_id )
     2756        : bbp_get_topic_id( $topic_id );
    27602757
    27612758    // Get replies of topic if not passed
     
    27972794
    27982795    // If it's a reply, then get the parent (topic id)
    2799     if ( bbp_is_reply( $topic_id ) ) {
    2800         $topic_id = bbp_get_reply_topic_id( $topic_id );
    2801     } else {
    2802         $topic_id = bbp_get_topic_id( $topic_id );
    2803     }
     2796    $topic_id = bbp_is_reply( $topic_id )
     2797        ? bbp_get_reply_topic_id( $topic_id )
     2798        : bbp_get_topic_id( $topic_id );
    28042799
    28052800    // Get replies of topic
     
    28412836
    28422837    // If it's a reply, then get the parent (topic id)
    2843     if ( bbp_is_reply( $topic_id ) ) {
    2844         $topic_id = bbp_get_reply_topic_id( $topic_id );
    2845     } else {
    2846         $topic_id = bbp_get_topic_id( $topic_id );
    2847     }
    2848 
     2838    $topic_id = bbp_is_reply( $topic_id )
     2839        ? bbp_get_reply_topic_id( $topic_id )
     2840        : bbp_get_topic_id( $topic_id );
     2841
     2842    // Get last public active id if not passed
    28492843    if ( empty( $active_id ) ) {
    28502844        $active_id = bbp_get_public_child_last_id( $topic_id, bbp_get_reply_post_type() );
     
    28862880
    28872881    // If it's a reply, then get the parent (topic id)
    2888     if ( bbp_is_reply( $topic_id ) ) {
    2889         $topic_id = bbp_get_reply_topic_id( $topic_id );
    2890     } else {
    2891         $topic_id = bbp_get_topic_id( $topic_id );
    2892     }
     2882    $topic_id = bbp_is_reply( $topic_id )
     2883        ? bbp_get_reply_topic_id( $topic_id )
     2884        : bbp_get_topic_id( $topic_id );
    28932885
    28942886    // Check time and use current if empty
     
    30193011
    30203012    // If it's a reply, then get the parent (topic id)
    3021     if ( bbp_is_reply( $topic_id ) ) {
    3022         $topic_id = bbp_get_reply_topic_id( $topic_id );
    3023     } elseif ( bbp_is_topic( $topic_id ) ) {
    3024         $topic_id = bbp_get_topic_id( $topic_id );
    3025     } else {
    3026         return;
    3027     }
     3013    $topic_id = bbp_is_reply( $topic_id )
     3014        ? bbp_get_reply_topic_id( $topic_id )
     3015        : bbp_get_topic_id( $topic_id );
    30283016
    30293017    // Query the DB to get anonymous replies in this topic
     
    34523440
    34533441/**
    3454  * Retreive tags to a topic from post meta before it's unmarked as spam so they.
     3442 * Retrieve tags to a topic from post meta before it's unmarked as spam so they.
    34553443 *
    34563444 * Usually you'll want to do this before the topic itself is unmarked as spam.
  • trunk/src/includes/users/engagements.php

    r6529 r6534  
    196196    $topic_id = bbp_get_topic_id( $topic_id );
    197197    $bbp_db   = bbp_db();
     198    $statii   = "'" . implode( "', '", bbp_get_public_topic_statuses() ) . "'";
    198199
    199200    // A cool UNION query!
     
    201202SELECT DISTINCT( post_author ) FROM (
    202203    SELECT post_author FROM {$bbp_db->posts}
    203         WHERE ( ID = %d AND post_type = %s )
     204        WHERE ( ID = %d AND post_status IN ({$statii}) AND post_type = %s )
    204205UNION
    205206    SELECT post_author FROM {$bbp_db->posts}
    206         WHERE ( post_parent = %d AND post_type = %s )
     207        WHERE ( post_parent = %d AND post_status = %s AND post_type = %s )
    207208) as u1";
    208209
    209210    // Prepare & get results
    210     $query   = $bbp_db->prepare( $sql, $topic_id, bbp_get_topic_post_type(), $topic_id, bbp_get_reply_post_type() );
     211    $query   = $bbp_db->prepare( $sql, $topic_id, bbp_get_topic_post_type(), $topic_id, bbp_get_public_status_id(), bbp_get_reply_post_type() );
    211212    $results = $bbp_db->get_col( $query );
    212213
     
    439440function bbp_update_topic_engagements( $topic_id = 0 ) {
    440441
    441     // Check post type
     442    // Is a reply
    442443    if ( bbp_is_reply( $topic_id ) ) {
     444
     445        // Bail if reply isn't published
     446        if ( ! bbp_is_reply_published( $topic_id ) ) {
     447            return;
     448        }
     449
    443450        $author_id = bbp_get_reply_author_id( $topic_id );
    444451        $topic_id  = bbp_get_reply_topic_id( $topic_id );
     452
     453    // Is a topic
    445454    } elseif ( bbp_is_topic( $topic_id ) ) {
    446455        $author_id = bbp_get_topic_author_id( $topic_id );
    447456        $topic_id  = bbp_get_topic_id( $topic_id );
     457
     458    // Is unknown
    448459    } else {
     460        return;
     461    }
     462
     463    // Bail if topic is not public
     464    if ( ! bbp_is_topic_public( $topic_id ) ) {
    449465        return;
    450466    }
Note: See TracChangeset for help on using the changeset viewer.