Ticket #2586: tools-fix.patch
| File tools-fix.patch, 3.5 KB (added by , 12 years ago) |
|---|
-
src/includes/admin/tools.php
325 325 $statement = __( 'Counting the number of replies in each topic… %s', 'bbpress' ); 326 326 $result = __( 'Failed!', 'bbpress' ); 327 327 328 $sql_delete = "DELETE FROM `{$wpdb->postmeta}` WHERE `meta_key` = '_bbp_reply_count';";329 if ( is_wp_error( $wpdb->query( $sql_delete ) ) )330 return array( 1, sprintf( $statement, $result ) );331 332 328 // Post types and status 333 329 $tpt = bbp_get_topic_post_type(); 334 330 $rpt = bbp_get_reply_post_type(); … … 335 331 $pps = bbp_get_public_status_id(); 336 332 $cps = bbp_get_closed_status_id(); 337 333 334 // Get an array of topic id's and delete the meta key _bbp_reply_count for each 335 $topics = $wpdb->get_results( "SELECT `ID` FROM `{$wpdb->posts}` WHERE `post_type` = '{$tpt}';", OBJECT_K ); 336 337 if ( !empty( $topics ) ) { 338 $topic_ids = array(); 339 foreach ( $topics as $key => $value ) { 340 $topic_ids[] = $key; 341 } 342 343 $topic_ids = implode( ", ", $topic_ids ); 344 $sql_delete = "DELETE FROM `{$wpdb->postmeta}` WHERE `post_id` IN ({$topic_ids}) AND `meta_key` = '_bbp_reply_count';"; 345 if ( is_wp_error( $wpdb->query( $sql_delete ) ) ) { 346 return array( 1, sprintf( $statement, $result ) ); 347 } 348 } 349 350 // Cleanup 351 unset( $topics, $topic_ids, $sql_delete ); 352 353 // Recalculate the meta key _bbp_reply_count for each topic 338 354 $sql = "INSERT INTO `{$wpdb->postmeta}` (`post_id`, `meta_key`, `meta_value`) ( 339 355 SELECT `topics`.`ID` AS `post_id`, '_bbp_reply_count' AS `meta_key`, COUNT(`replies`.`ID`) As `meta_value` 340 356 FROM `{$wpdb->posts}` AS `topics` … … 346 362 AND `topics`.`post_status` IN ( '{$pps}', '{$cps}' ) 347 363 GROUP BY `topics`.`ID`);"; 348 364 349 if ( is_wp_error( $wpdb->query( $sql ) ) ) 365 if ( is_wp_error( $wpdb->query( $sql ) ) ) { 350 366 return array( 2, sprintf( $statement, $result ) ); 367 } 351 368 352 369 return array( 0, sprintf( $statement, __( 'Complete!', 'bbpress' ) ) ); 353 370 } … … 619 636 $statement = __( 'Counting the number of replies in each forum… %s', 'bbpress' ); 620 637 $result = __( 'Failed!', 'bbpress' ); 621 638 622 $sql_delete = "DELETE FROM `{$wpdb->postmeta}` WHERE `meta_key` IN ( '_bbp_reply_count', '_bbp_total_reply_count' );"; 623 if ( is_wp_error( $wpdb->query( $sql_delete ) ) ) 624 return array( 1, sprintf( $statement, $result ) ); 639 // Post types and status 640 $fpt = bbp_get_forum_post_type(); 625 641 642 // Get an array of forum id's and delete the meta key _bbp_reply_count for each 643 $forums = $wpdb->get_results( "SELECT `ID` FROM `{$wpdb->posts}` WHERE `post_type` = '{$fpt}';", OBJECT_K ); 644 645 if ( !empty( $forums ) ) { 646 $forums_ids = array(); 647 foreach ( $forums as $key => $value ) { 648 $forums_ids[] = $key; 649 } 650 651 $forums_ids = implode( ", ", $forums_ids ); 652 $sql_delete = "DELETE FROM `{$wpdb->postmeta}` WHERE `post_id` IN ({$forums_ids}) AND `meta_key` = '_bbp_reply_count';"; 653 if ( is_wp_error( $wpdb->query( $sql_delete ) ) ) { 654 return array( 1, sprintf( $statement, $result ) ); 655 } 656 } 657 658 // Cleanup 659 unset( $forums, $forums_ids, $sql_delete ); 660 661 // Recalculate the meta key _bbp_reply_count for each forum 626 662 $forums = get_posts( array( 'post_type' => bbp_get_forum_post_type(), 'numberposts' => -1 ) ); 627 663 if ( !empty( $forums ) ) { 628 664 foreach ( $forums as $forum ) { … … 1484 1520 bbp_admin_tools_feedback( $message ); 1485 1521 } 1486 1522 } 1487 } 1488 No newline at end of file 1523 }
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)