Ticket #2586: tools-fix.2.patch
| File tools-fix.2.patch, 3.0 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 // Delete the meta key _bbp_reply_count for each topic 335 $sql_delete = "DELETE `postmeta` FROM `{$wpdb->postmeta}` AS `postmeta` 336 LEFT JOIN `{$wpdb->posts}` AS `posts` ON `posts`.`ID` = `postmeta`.`post_id` 337 WHERE `posts`.`post_type` = '{$tpt}' 338 AND `postmeta`.`meta_key` = '_bbp_reply_count'"; 339 if ( is_wp_error( $wpdb->query( $sql_delete ) ) ) { 340 return array( 1, sprintf( $statement, $result ) ); 341 } 342 343 // Recalculate the meta key _bbp_reply_count for each topic 338 344 $sql = "INSERT INTO `{$wpdb->postmeta}` (`post_id`, `meta_key`, `meta_value`) ( 339 345 SELECT `topics`.`ID` AS `post_id`, '_bbp_reply_count' AS `meta_key`, COUNT(`replies`.`ID`) As `meta_value` 340 346 FROM `{$wpdb->posts}` AS `topics` … … 346 352 AND `topics`.`post_status` IN ( '{$pps}', '{$cps}' ) 347 353 GROUP BY `topics`.`ID`);"; 348 354 349 if ( is_wp_error( $wpdb->query( $sql ) ) ) 355 if ( is_wp_error( $wpdb->query( $sql ) ) ) { 350 356 return array( 2, sprintf( $statement, $result ) ); 357 } 351 358 352 359 return array( 0, sprintf( $statement, __( 'Complete!', 'bbpress' ) ) ); 353 360 } … … 619 626 $statement = __( 'Counting the number of replies in each forum… %s', 'bbpress' ); 620 627 $result = __( 'Failed!', 'bbpress' ); 621 628 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 ) ) ) 629 // Post types and status 630 $fpt = bbp_get_forum_post_type(); 631 632 // Delete the meta keys _bbp_reply_count and _bbp_total_reply_count for each forum 633 $sql_delete = "DELETE `postmeta` FROM `{$wpdb->postmeta}` AS `postmeta` 634 LEFT JOIN `{$wpdb->posts}` AS `posts` ON `posts`.`ID` = `postmeta`.`post_id` 635 WHERE `posts`.`post_type` = '{$fpt}' 636 AND `postmeta`.`meta_key` = '_bbp_reply_count' 637 OR `postmeta`.`meta_key` = '_bbp_total_reply_count'"; 638 639 if ( is_wp_error( $wpdb->query( $sql_delete ) ) ) { 624 640 return array( 1, sprintf( $statement, $result ) ); 641 } 625 642 643 // Recalculate the metas key _bbp_reply_count and _bbp_total_reply_count for each forum 626 644 $forums = get_posts( array( 'post_type' => bbp_get_forum_post_type(), 'numberposts' => -1 ) ); 627 645 if ( !empty( $forums ) ) { 628 646 foreach ( $forums as $forum ) { … … 1484 1502 bbp_admin_tools_feedback( $message ); 1485 1503 } 1486 1504 } 1487 } 1488 No newline at end of file 1505 }
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)