Skip to:
Content

bbPress.org

Ticket #2849: 2849.diff

File 2849.diff, 3.7 KB (added by netweb, 9 years ago)
  • tests/phpunit/testcases/admin/tools.php

     
    166166
    167167        /**
    168168         * @covers ::bbp_admin_repair_topic_hidden_reply_count
    169          * @todo   Implement test_bbp_admin_repair_topic_hidden_reply_count().
    170169         */
    171170        public function test_bbp_admin_repair_topic_hidden_reply_count() {
    172                 // Remove the following lines when you implement this test.
    173                 $this->markTestIncomplete(
    174                         'This test has not been implemented yet.'
    175                 );
     171
     172                $f = $this->factory->forum->create();
     173
     174                $t = $this->factory->topic->create( array(
     175                        'post_parent' => $f,
     176                        'topic_meta' => array(
     177                                'forum_id' => $f,
     178                        ),
     179                ) );
     180
     181                $r = $this->factory->reply->create( array(
     182                        'post_parent' => $t,
     183                        'reply_meta' => array(
     184                                'forum_id' => $f,
     185                                'topic_id' => $t,
     186                        ),
     187                ) );
     188
     189                $count = bbp_get_topic_reply_count( $t, true );
     190                $this->assertSame( 1, $count );
     191
     192                $r = $this->factory->reply->create_many( 3, array(
     193                        'post_parent' => $t,
     194                        'reply_meta' => array(
     195                                'forum_id' => $f,
     196                                'topic_id' => $t,
     197                        ),
     198                ) );
     199
     200                bbp_spam_reply( $r[0] );
     201                bbp_unapprove_reply( $r[2] );
     202
     203                $count = bbp_get_topic_reply_count_hidden( $t, true );
     204                $this->assertSame( 2, $count );
     205
     206                // Delete the topic _bbp_reply_count_hidden meta key.
     207                $this->assertTrue( delete_post_meta_by_key( '_bbp_reply_count_hidden' ) );
     208
     209                $count = bbp_get_topic_reply_count_hidden( $t, true );
     210                $this->assertSame( 0, $count );
     211
     212                // Repair the topic hidden reply count meta.
     213                bbp_admin_repair_topic_hidden_reply_count();
     214
     215                bbp_clean_post_cache( $t );
     216
     217                $count = bbp_get_topic_reply_count_hidden( $t, true );
     218                $this->assertSame( 2, $count );
    176219        }
    177220
    178221        /**
  • src/includes/admin/tools.php

     
    10621062 * @uses bbp_get_reply_post_type() To get the reply post type
    10631063 * @uses bbp_get_trash_status_id() To get the trash status id
    10641064 * @uses bbp_get_spam_status_id() To get the spam status id
     1065 * @uses bbp_get_pending_status_id() To get the pending status id
    10651066 * @return array An array of the status code and the message
    10661067 */
    10671068function bbp_admin_repair_topic_hidden_reply_count() {
     
    10681069
    10691070        // Define variables
    10701071        $bbp_db    = bbp_db();
    1071         $statement = __( 'Counting the number of spammed and trashed replies in each topic… %s', 'bbpress' );
     1072        $statement = __( 'Counting the number of pending, spammed, and trashed replies in each topic… %s', 'bbpress' );
    10721073        $result    = __( 'Failed!', 'bbpress' );
    10731074
    10741075        $sql_delete = "DELETE FROM `{$bbp_db->postmeta}` WHERE `meta_key` = '_bbp_reply_count_hidden';";
     
    10801081        $rpt = bbp_get_reply_post_type();
    10811082        $tps = bbp_get_trash_status_id();
    10821083        $sps = bbp_get_spam_status_id();
     1084        $pps = bbp_get_pending_status_id();
    10831085
    1084         $sql = "INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`) (SELECT `post_parent`, '_bbp_reply_count_hidden', COUNT(`post_status`) as `meta_value` FROM `{$bbp_db->posts}` WHERE `post_type` = '{$rpt}' AND `post_status` IN ( '{$tps}', '{$sps}' ) GROUP BY `post_parent`);";
     1086        $sql = "INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`) (SELECT `post_parent`, '_bbp_reply_count_hidden', COUNT(`post_status`) as `meta_value` FROM `{$bbp_db->posts}` WHERE `post_type` = '{$rpt}' AND `post_status` IN ( '{$tps}', '{$sps}', '{$pps}' ) GROUP BY `post_parent`);";
    10851087        if ( is_wp_error( $bbp_db->query( $sql ) ) ) {
    10861088                return array( 2, sprintf( $statement, $result ) );
    10871089        }