Skip to:
Content

bbPress.org

Ticket #2259: topics-functions.patch

File topics-functions.patch, 4.1 KB (added by alex-ye, 12 years ago)

Stick topic in the new forum only when it was sticky in the old forum + Some enhancements

  • functions.php

    # This patch file was generated by NetBeans IDE
    # Following Index: paths are relative to: \includes\topics
    # It uses platform neutral UTF-8 encoding and \n newlines.
    # Above lines and this line are ignored by the patching process.
     
    954954        $old_forum_id = bbp_get_forum_id( $old_forum_id );
    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
    959962        // Get forum stickies
     
    964967
    965968                // Define local variables
    966969                $updated_stickies = array();
    967 
     970               
    968971                // Loop through stickies of forum
    969                 foreach ( $old_stickies as $sticky_topic_id ) {
     972                foreach ( (array) $old_stickies as $sticky_topic_id ) {
    970973
    971974                        // Add non-matches to the updated array
    972975                        if ( $topic_id != $sticky_topic_id ) {
     
    974977                        }
    975978                }
    976979
    977                 // No more stickies so delete the beta
    978                 if ( empty( $updated_stickies ) ) {
    979                         delete_post_meta ( $old_forum_id, '_bbp_sticky_topics' );
     980                if ( $updated_stickies != $old_stickies ) {
     981                 
     982                        // No more stickies so delete the beta
     983                        if ( empty( $updated_stickies ) ) {
     984                                delete_post_meta ( $old_forum_id, '_bbp_sticky_topics' );
    980985
    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 );
     986                        // Still stickies so update the meta
     987                        } else {
     988                                update_post_meta( $old_forum_id, '_bbp_sticky_topics', $updated_stickies );
     989                        }
     990                       
     991                        // Topic was sticky, so restick in new forum
     992                        bbp_stick_topic( $topic_id );
     993                }
    988994        }
    989995
    990996        /** Topic Replies *********************************************************/
     
    9961002        foreach ( $replies as $reply_id )
    9971003                bbp_update_reply_forum_id( $reply_id, $new_forum_id );
    9981004
    999         // Forum topic meta
    1000         bbp_update_topic_forum_id( $topic_id, $new_forum_id );
    1001 
    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 ) ) ) );
     1008        $old_forum_ancestors = array_values( array_unique( array_merge( array( $old_forum_id ), (array) get_post_ancestors( $old_forum_id ) ) ) );
    10061009
    10071010        // Loop through ancestors
    1008         if ( !empty( $ancestors ) ) {
    1009                 foreach ( $ancestors as $ancestor ) {
     1011        if ( !empty( $old_forum_ancestors ) ) {
     1012                foreach ( $old_forum_ancestors as $ancestor ) {
    10101013
    10111014                        // If ancestor is a forum, update counts
    10121015                        if ( bbp_is_forum( $ancestor ) ) {
     
    10221025        /** New forum_id **********************************************************/
    10231026
    10241027        // Make sure we're not walking twice
    1025         if ( !in_array( $new_forum_id, $ancestors ) ) {
     1028        if ( !in_array( $new_forum_id, $old_forum_ancestors ) ) {
    10261029
    10271030                // Get topic ancestors
    1028                 $ancestors = array_values( array_unique( array_merge( array( $new_forum_id ), (array) get_post_ancestors( $new_forum_id ) ) ) );
     1031                $new_forum_ancestors = array_values( array_unique( array_merge( array( $new_forum_id ), (array) get_post_ancestors( $new_forum_id ) ) ) );
     1032               
     1033                // Make sure we're not walking twice
     1034                $new_forum_ancestors = array_diff( $new_forum_ancestors, $old_forum_ancestors );
    10291035
    10301036                // Loop through ancestors
    1031                 if ( !empty( $ancestors ) ) {
    1032                         foreach ( $ancestors as $ancestor ) {
     1037                if ( !empty( $new_forum_ancestors ) ) {
     1038                        foreach ( $new_forum_ancestors as $ancestor ) {
    10331039
    10341040                                // If ancestor is a forum, update counts
    10351041                                if ( bbp_is_forum( $ancestor ) ) {