Skip to:
Content

bbPress.org

Changeset 7600


Ignore:
Timestamp:
09/19/2026 12:08:11 AM (3 days ago)
Author:
johnjamesjacoby
Message:

Importers: Preserve source counts during conversion.

Prevent post-status transition callbacks from incrementing imported forum and topic counts again while converted posts are inserted. This restores converter behavior predating centralized count synchronization and fixes doubled PHPWind counts found by database-backed import testing.

In branches/2.6, for 2.6.18.

See #3686.

Location:
branches/2.6
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/2.6/src/includes/admin/classes/class-bbp-converter-base.php

    r7598 r7600  
    635635
    636636                                                        default :
    637                                                                 $post_id = wp_insert_post( $insert_post, true );
     637                                                                $post_id = $this->insert_post( $insert_post );
    638638
    639639                                                                if ( is_numeric( $post_id ) ) {
     
    693693
    694694        /**
     695         * Insert a converted post without changing imported counts.
     696         *
     697         * Converter field maps include the source forum and topic counts. Prevent
     698         * post-status transition callbacks from incrementing those counts again as
     699         * each converted topic and reply is inserted.
     700         *
     701         * @since 2.6.18
     702         *
     703         * @param array $post_data Converted post data.
     704         * @return int|WP_Error Post ID on success, WP_Error on failure.
     705         */
     706        protected function insert_post( $post_data = array() ) {
     707                $suppress_count_updates = function () {
     708                        return false;
     709                };
     710
     711                add_filter( 'bbp_pre_update_counts_on_transition_post_status', $suppress_count_updates );
     712
     713                try {
     714                        $post_id = wp_insert_post( $post_data, true );
     715                } finally {
     716                        remove_filter( 'bbp_pre_update_counts_on_transition_post_status', $suppress_count_updates );
     717                }
     718
     719                return $post_id;
     720        }
     721
     722        /**
    695723         * This method converts old forum hierarchy to new bbPress hierarchy.
    696724         */
  • branches/2.6/tests/phpunit/testcases/admin/converters/base.php

    r7588 r7600  
    2222        public function get_pass_array( $value ) {
    2323                return $this->unserialize_pass( $value );
     24        }
     25
     26        public function insert_converted_post( $post_data ) {
     27                return $this->insert_post( $post_data );
    2428        }
    2529}
     
    6771
    6872        /**
     73         * @covers BBP_Converter_Base::insert_post
     74         * @ticket BBP3686
     75         */
     76        public function test_insert_post_does_not_increment_imported_counts() {
     77                $converter = new BBP_Tests_Admin_Converters_Base_Converter();
     78                $forum_id  = $this->factory->forum->create();
     79
     80                update_post_meta( $forum_id, '_bbp_topic_count', 4 );
     81
     82                $topic_id = $converter->insert_converted_post(
     83                        array(
     84                                'post_type'   => bbp_get_topic_post_type(),
     85                                'post_status' => bbp_get_public_status_id(),
     86                                'post_parent' => $forum_id,
     87                                'post_title'  => 'Converted topic',
     88                        )
     89                );
     90
     91                $this->assertIsInt( $topic_id );
     92                $this->assertSame( 4, bbp_get_forum_topic_count( $forum_id, false, true ) );
     93                $this->assertNull( apply_filters( 'bbp_pre_update_counts_on_transition_post_status', null, 'publish', 'new', get_post( $topic_id ) ) );
     94        }
     95
     96        /**
    6997         * @covers BBP_Converter_Base::unserialize_pass
    7098         * @ticket BBP3684
Note: See TracChangeset for help on using the changeset viewer.