Changeset 3890 for branches/plugin/bbp-admin/bbp-tools.php
- Timestamp:
- 05/07/2012 12:09:05 AM (15 years ago)
- File:
-
- 1 edited
-
branches/plugin/bbp-admin/bbp-tools.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/plugin/bbp-admin/bbp-tools.php
r3887 r3890 365 365 366 366 /** 367 * Recount topic repliedby the users368 * 369 * @since bbPress (r 2613)367 * Recount topics by the users 368 * 369 * @since bbPress (r3889) 370 370 * 371 371 * @uses bbp_get_reply_post_type() To get the reply post type … … 374 374 * @return array An array of the status code and the message 375 375 */ 376 function bbp_admin_repair_user_reply_count() { 377 global $wpdb; 378 379 $statement = __( 'Counting the number of topics to which each user has replied… %s', 'bbpress' ); 380 $result = __( 'Failed!', 'bbpress' ); 381 382 $sql_select = "SELECT `post_author`, COUNT(DISTINCT `ID`) as `_count` FROM `{$wpdb->posts}` WHERE `post_type` = '" . bbp_get_reply_post_type() . "' AND `post_status` = '" . bbp_get_public_status_id() . "' GROUP BY `post_author`;"; 376 function bbp_admin_repair_user_topic_count() { 377 global $wpdb; 378 379 $statement = __( 'Counting the number of topics each user has created… %s', 'bbpress' ); 380 $result = __( 'Failed!', 'bbpress' ); 381 $sql_select = "SELECT `post_author`, COUNT(DISTINCT `ID`) as `_count` FROM `{$wpdb->posts}` WHERE `post_type` = '" . bbp_get_topic_post_type() . "' AND `post_status` = '" . bbp_get_public_status_id() . "' GROUP BY `post_author`;"; 383 382 $insert_rows = $wpdb->get_results( $sql_select ); 384 383 … … 388 387 $insert_values = array(); 389 388 foreach ( $insert_rows as $insert_row ) 390 $insert_values[] = "('{$insert_row->post_author}', '_bbp_topic s_replied', '{$insert_row->_count}')";389 $insert_values[] = "('{$insert_row->post_author}', '_bbp_topic_count', '{$insert_row->_count}')"; 391 390 392 391 if ( !count( $insert_values ) ) 393 392 return array( 2, sprintf( $statement, $result ) ); 394 393 395 $sql_delete = "DELETE FROM `{$wpdb->usermeta}` WHERE `meta_key` = '_bbp_topic s_replied';";394 $sql_delete = "DELETE FROM `{$wpdb->usermeta}` WHERE `meta_key` = '_bbp_topic_count';"; 396 395 if ( is_wp_error( $wpdb->query( $sql_delete ) ) ) 397 396 return array( 3, sprintf( $statement, $result ) ); … … 402 401 $sql_insert = "INSERT INTO `{$wpdb->usermeta}` (`user_id`, `meta_key`, `meta_value`) VALUES $chunk;"; 403 402 404 if ( is_wp_error( $wpdb->query( $sql_insert ) ) ) 403 if ( is_wp_error( $wpdb->query( $sql_insert ) ) ) { 405 404 return array( 4, sprintf( $statement, $result ) ); 405 } 406 } 407 408 $result = __( 'Complete!', 'bbpress' ); 409 return array( 0, sprintf( $statement, $result ) ); 410 } 411 412 /** 413 * Recount topic replied by the users 414 * 415 * @since bbPress (r2613) 416 * 417 * @uses bbp_get_reply_post_type() To get the reply post type 418 * @uses wpdb::query() To run our recount sql queries 419 * @uses is_wp_error() To check if the executed query returned {@link WP_Error} 420 * @return array An array of the status code and the message 421 */ 422 function bbp_admin_repair_user_reply_count() { 423 global $wpdb; 424 425 $statement = __( 'Counting the number of topics to which each user has replied… %s', 'bbpress' ); 426 $result = __( 'Failed!', 'bbpress' ); 427 $sql_select = "SELECT `post_author`, COUNT(DISTINCT `ID`) as `_count` FROM `{$wpdb->posts}` WHERE `post_type` = '" . bbp_get_reply_post_type() . "' AND `post_status` = '" . bbp_get_public_status_id() . "' GROUP BY `post_author`;"; 428 $insert_rows = $wpdb->get_results( $sql_select ); 429 430 if ( is_wp_error( $insert_rows ) ) 431 return array( 1, sprintf( $statement, $result ) ); 432 433 $insert_values = array(); 434 foreach ( $insert_rows as $insert_row ) 435 $insert_values[] = "('{$insert_row->post_author}', '_bbp_reply_count', '{$insert_row->_count}')"; 436 437 if ( !count( $insert_values ) ) 438 return array( 2, sprintf( $statement, $result ) ); 439 440 $sql_delete = "DELETE FROM `{$wpdb->usermeta}` WHERE `meta_key` = '_bbp_reply_count';"; 441 if ( is_wp_error( $wpdb->query( $sql_delete ) ) ) 442 return array( 3, sprintf( $statement, $result ) ); 443 444 $insert_values = array_chunk( $insert_values, 10000 ); 445 foreach ( $insert_values as $chunk ) { 446 $chunk = "\n" . join( ",\n", $chunk ); 447 $sql_insert = "INSERT INTO `{$wpdb->usermeta}` (`user_id`, `meta_key`, `meta_value`) VALUES $chunk;"; 448 449 if ( is_wp_error( $wpdb->query( $sql_insert ) ) ) { 450 return array( 4, sprintf( $statement, $result ) ); 451 } 406 452 } 407 453
Note:
See TracChangeset
for help on using the changeset viewer.