Skip to:
Content

bbPress.org

Changeset 4816


Ignore:
Timestamp:
03/17/2013 01:27:17 PM (12 years ago)
Author:
johnjamesjacoby
Message:

In bbp_move_topic_handler(), when moving a topic from one forum to another, recalculate sticky topics for each forum, and update them accordingly. Also modify the logic used to update ancestor forums, to avoid running update routine multiple times on the same forum. Props alex-ye. Fixes #2259.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/topics/functions.php

    r4810 r4816  
    955955    $new_forum_id = bbp_get_forum_id( $new_forum_id );
    956956
     957    // Update topic forum's ID
     958    bbp_update_topic_forum_id( $topic_id, $new_forum_id );
     959
    957960    /** Stickies **************************************************************/
    958961
     
    966969        $updated_stickies = array();
    967970
    968         // Loop through stickies of forum
    969         foreach ( $old_stickies as $sticky_topic_id ) {
    970 
    971             // Add non-matches to the updated array
     971        // Loop through stickies of forum and add misses to the updated array
     972        foreach ( (array) $old_stickies as $sticky_topic_id ) {
    972973            if ( $topic_id != $sticky_topic_id ) {
    973974                $updated_stickies[] = $sticky_topic_id;
     
    975976        }
    976977
    977         // No more stickies so delete the beta
    978         if ( empty( $updated_stickies ) ) {
    979             delete_post_meta ( $old_forum_id, '_bbp_sticky_topics' );
    980 
    981         // Still stickies so update the meta
    982         } else {
    983             update_post_meta( $old_forum_id, '_bbp_sticky_topics', $updated_stickies );
    984         }
    985 
    986         // Topic was sticky, so restick in new forum
    987         bbp_stick_topic( $topic_id );
     978        // If stickies are different, update or delete them
     979        if ( $updated_stickies != $old_stickies ) {
     980
     981            // No more stickies so delete the meta
     982            if ( empty( $updated_stickies ) ) {
     983                delete_post_meta( $old_forum_id, '_bbp_sticky_topics' );
     984
     985            // Still stickies so update the meta
     986            } else {
     987                update_post_meta( $old_forum_id, '_bbp_sticky_topics', $updated_stickies );
     988            }
     989
     990            // Topic was sticky, so restick in new forum
     991            bbp_stick_topic( $topic_id );
     992        }
    988993    }
    989994
     
    994999
    9951000    // Update the forum_id of all replies in the topic
    996     foreach ( $replies as $reply_id )
     1001    foreach ( $replies as $reply_id ) {
    9971002        bbp_update_reply_forum_id( $reply_id, $new_forum_id );
    998 
    999     // Forum topic meta
    1000     bbp_update_topic_forum_id( $topic_id, $new_forum_id );
     1003    }
    10011004
    10021005    /** Old forum_id **********************************************************/
    10031006
    10041007    // Get topic ancestors
    1005     $ancestors = array_values( array_unique( array_merge( array( $old_forum_id ), (array) get_post_ancestors( $old_forum_id ) ) ) );
    1006 
    1007     // Loop through ancestors
    1008     if ( !empty( $ancestors ) ) {
    1009         foreach ( $ancestors as $ancestor ) {
    1010 
    1011             // If ancestor is a forum, update counts
     1008    $old_forum_ancestors = array_values( array_unique( array_merge( array( $old_forum_id ), (array) get_post_ancestors( $old_forum_id ) ) ) );
     1009
     1010    // Loop through ancestors and update them
     1011    if ( !empty( $old_forum_ancestors ) ) {
     1012        foreach ( $old_forum_ancestors as $ancestor ) {
    10121013            if ( bbp_is_forum( $ancestor ) ) {
    1013 
    1014                 // Update the forum
    10151014                bbp_update_forum( array(
    10161015                    'forum_id' => $ancestor,
     
    10231022
    10241023    // Make sure we're not walking twice
    1025     if ( !in_array( $new_forum_id, $ancestors ) ) {
     1024    if ( !in_array( $new_forum_id, $old_forum_ancestors ) ) {
    10261025
    10271026        // Get topic ancestors
    1028         $ancestors = array_values( array_unique( array_merge( array( $new_forum_id ), (array) get_post_ancestors( $new_forum_id ) ) ) );
    1029 
    1030         // Loop through ancestors
    1031         if ( !empty( $ancestors ) ) {
    1032             foreach ( $ancestors as $ancestor ) {
    1033 
    1034                 // If ancestor is a forum, update counts
     1027        $new_forum_ancestors = array_values( array_unique( array_merge( array( $new_forum_id ), (array) get_post_ancestors( $new_forum_id ) ) ) );
     1028
     1029        // Make sure we're not walking twice
     1030        $new_forum_ancestors = array_diff( $new_forum_ancestors, $old_forum_ancestors );
     1031
     1032        // Loop through ancestors and update them
     1033        if ( !empty( $new_forum_ancestors ) ) {
     1034            foreach ( $new_forum_ancestors as $ancestor ) {
    10351035                if ( bbp_is_forum( $ancestor ) ) {
    1036 
    1037                     // Update the forum
    10381036                    bbp_update_forum( array(
    10391037                        'forum_id' => $ancestor,
     
    10981096
    10991097    // Topic id
    1100     if ( empty( $_POST['bbp_topic_id'] ) )
     1098    if ( empty( $_POST['bbp_topic_id'] ) ) {
    11011099        bbp_add_error( 'bbp_merge_topic_source_id', __( '<strong>ERROR</strong>: Topic ID not found.', 'bbpress' ) );
    1102     else
     1100    } else {
    11031101        $source_topic_id = (int) $_POST['bbp_topic_id'];
     1102    }
    11041103
    11051104    // Nonce check
Note: See TracChangeset for help on using the changeset viewer.