Changeset 5367
- Timestamp:
- 06/05/2014 09:29:52 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.5/includes/admin/tools.php
r5175 r5367 164 164 15 => array( 'bbp-sync-all-topics-forums', __( 'Recalculate last activity in each topic and forum', 'bbpress' ), 'bbp_admin_repair_freshness' ), 165 165 20 => array( 'bbp-sync-all-topics-sticky', __( 'Recalculate the sticky relationship of each topic', 'bbpress' ), 'bbp_admin_repair_sticky' ), 166 25 => array( 'bbp-group-forums', __( 'Repair BuddyPress Group Forum relationships', 'bbpress' ), 'bbp_admin_repair_group_forum_relationship' ), 167 30 => array( 'bbp-forum-topics', __( 'Count topics in each forum', 'bbpress' ), 'bbp_admin_repair_forum_topic_count' ), 168 35 => array( 'bbp-forum-replies', __( 'Count replies in each forum', 'bbpress' ), 'bbp_admin_repair_forum_reply_count' ), 169 40 => array( 'bbp-topic-replies', __( 'Count replies in each topic', 'bbpress' ), 'bbp_admin_repair_topic_reply_count' ), 170 45 => array( 'bbp-topic-voices', __( 'Count voices in each topic', 'bbpress' ), 'bbp_admin_repair_topic_voice_count' ), 171 50 => array( 'bbp-topic-hidden-replies', __( 'Count spammed & trashed replies in each topic', 'bbpress' ), 'bbp_admin_repair_topic_hidden_reply_count' ), 172 55 => array( 'bbp-user-topics', __( 'Count topics for each user', 'bbpress' ), 'bbp_admin_repair_user_topic_count' ), 173 60 => array( 'bbp-user-replies', __( 'Count replies for each user', 'bbpress' ), 'bbp_admin_repair_user_reply_count' ), 174 65 => array( 'bbp-user-favorites', __( 'Remove trashed topics from user favorites', 'bbpress' ), 'bbp_admin_repair_user_favorites' ), 175 70 => array( 'bbp-user-topic-subscriptions', __( 'Remove trashed topics from user subscriptions', 'bbpress' ), 'bbp_admin_repair_user_topic_subscriptions' ), 176 75 => array( 'bbp-user-forum-subscriptions', __( 'Remove trashed forums from user subscriptions', 'bbpress' ), 'bbp_admin_repair_user_forum_subscriptions' ), 177 80 => array( 'bbp-user-role-map', __( 'Remap existing users to default forum roles', 'bbpress' ), 'bbp_admin_repair_user_roles' ) 166 25 => array( 'bbp-sync-all-reply-positions', __( 'Recalculate the reply position hierarchy', 'bbpress' ), 'bbp_admin_repair_reply_menu_order' ), 167 30 => array( 'bbp-group-forums', __( 'Repair BuddyPress Group Forum relationships', 'bbpress' ), 'bbp_admin_repair_group_forum_relationship' ), 168 35 => array( 'bbp-forum-topics', __( 'Count topics in each forum', 'bbpress' ), 'bbp_admin_repair_forum_topic_count' ), 169 40 => array( 'bbp-forum-replies', __( 'Count replies in each forum', 'bbpress' ), 'bbp_admin_repair_forum_reply_count' ), 170 45 => array( 'bbp-topic-replies', __( 'Count replies in each topic', 'bbpress' ), 'bbp_admin_repair_topic_reply_count' ), 171 50 => array( 'bbp-topic-voices', __( 'Count voices in each topic', 'bbpress' ), 'bbp_admin_repair_topic_voice_count' ), 172 55 => array( 'bbp-topic-hidden-replies', __( 'Count spammed & trashed replies in each topic', 'bbpress' ), 'bbp_admin_repair_topic_hidden_reply_count' ), 173 60 => array( 'bbp-user-topics', __( 'Count topics for each user', 'bbpress' ), 'bbp_admin_repair_user_topic_count' ), 174 65 => array( 'bbp-user-replies', __( 'Count replies for each user', 'bbpress' ), 'bbp_admin_repair_user_reply_count' ), 175 70 => array( 'bbp-user-favorites', __( 'Remove trashed topics from user favorites', 'bbpress' ), 'bbp_admin_repair_user_favorites' ), 176 75 => array( 'bbp-user-topic-subscriptions', __( 'Remove trashed topics from user subscriptions', 'bbpress' ), 'bbp_admin_repair_user_topic_subscriptions' ), 177 80 => array( 'bbp-user-forum-subscriptions', __( 'Remove trashed forums from user subscriptions', 'bbpress' ), 'bbp_admin_repair_user_forum_subscriptions' ), 178 85 => array( 'bbp-user-role-map', __( 'Remap existing users to default forum roles', 'bbpress' ), 'bbp_admin_repair_user_roles' ) 178 179 ); 179 180 ksort( $repair_list ); … … 197 198 $statement = __( 'Counting the number of replies in each topic… %s', 'bbpress' ); 198 199 $result = __( 'Failed!', 'bbpress' ); 199 200 $sql_delete = "DELETE FROM `{$wpdb->postmeta}` WHERE `meta_key` = '_bbp_reply_count';";201 if ( is_wp_error( $wpdb->query( $sql_delete ) ) )202 return array( 1, sprintf( $statement, $result ) );203 200 204 201 // Post types and status … … 208 205 $cps = bbp_get_closed_status_id(); 209 206 207 // Delete the meta key _bbp_reply_count for each topic 208 $sql_delete = "DELETE `postmeta` FROM `{$wpdb->postmeta}` AS `postmeta` 209 LEFT JOIN `{$wpdb->posts}` AS `posts` ON `posts`.`ID` = `postmeta`.`post_id` 210 WHERE `posts`.`post_type` = '{$tpt}' 211 AND `postmeta`.`meta_key` = '_bbp_reply_count'"; 212 213 if ( is_wp_error( $wpdb->query( $sql_delete ) ) ) { 214 return array( 1, sprintf( $statement, $result ) ); 215 } 216 217 // Recalculate the meta key _bbp_reply_count for each topic 210 218 $sql = "INSERT INTO `{$wpdb->postmeta}` (`post_id`, `meta_key`, `meta_value`) ( 211 219 SELECT `topics`.`ID` AS `post_id`, '_bbp_reply_count' AS `meta_key`, COUNT(`replies`.`ID`) As `meta_value` … … 219 227 GROUP BY `topics`.`ID`);"; 220 228 221 if ( is_wp_error( $wpdb->query( $sql ) ) ) 229 if ( is_wp_error( $wpdb->query( $sql ) ) ) { 222 230 return array( 2, sprintf( $statement, $result ) ); 231 } 223 232 224 233 return array( 0, sprintf( $statement, __( 'Complete!', 'bbpress' ) ) ); … … 479 488 $result = __( 'Failed!', 'bbpress' ); 480 489 481 $sql_delete = "DELETE FROM `{$wpdb->postmeta}` WHERE `meta_key` IN ( '_bbp_reply_count', '_bbp_total_reply_count' );"; 482 if ( is_wp_error( $wpdb->query( $sql_delete ) ) ) 483 return array( 1, sprintf( $statement, $result ) ); 484 490 // Post type 491 $fpt = bbp_get_forum_post_type(); 492 493 // Delete the meta keys _bbp_reply_count and _bbp_total_reply_count for each forum 494 $sql_delete = "DELETE `postmeta` FROM `{$wpdb->postmeta}` AS `postmeta` 495 LEFT JOIN `{$wpdb->posts}` AS `posts` ON `posts`.`ID` = `postmeta`.`post_id` 496 WHERE `posts`.`post_type` = '{$fpt}' 497 AND `postmeta`.`meta_key` = '_bbp_reply_count' 498 OR `postmeta`.`meta_key` = '_bbp_total_reply_count'"; 499 500 if ( is_wp_error( $wpdb->query( $sql_delete ) ) ) { 501 return array( 1, sprintf( $statement, $result ) ); 502 } 503 504 // Recalculate the metas key _bbp_reply_count and _bbp_total_reply_count for each forum 485 505 $forums = get_posts( array( 'post_type' => bbp_get_forum_post_type(), 'numberposts' => -1 ) ); 486 506 if ( !empty( $forums ) ) { … … 1108 1128 1109 1129 // Complete results 1130 return array( 0, sprintf( $statement, __( 'Complete!', 'bbpress' ) ) ); 1131 } 1132 1133 /** 1134 * Recalculate reply menu order 1135 * 1136 * @since bbPress (r5367) 1137 * 1138 * @uses wpdb::query() To run our recount sql queries 1139 * @uses is_wp_error() To check if the executed query returned {@link WP_Error} 1140 * @uses bbp_get_reply_post_type() To get the reply post type 1141 * @uses bbp_update_reply_position() To update the reply position 1142 * @return array An array of the status code and the message 1143 */ 1144 function bbp_admin_repair_reply_menu_order() { 1145 global $wpdb; 1146 1147 $statement = __( 'Recalculating reply menu order … %s', 'bbpress' ); 1148 $result = __( 'No reply hierachy to recalculate!', 'bbpress' ); 1149 1150 // Post type 1151 $rpt = bbp_get_reply_post_type(); 1152 1153 // Get an array of reply id's to update the menu oder for each reply 1154 $replies = $wpdb->get_results( "SELECT `a`.`ID` FROM `{$wpdb->posts}` AS `a` 1155 INNER JOIN ( 1156 SELECT `menu_order`, `post_parent` 1157 FROM `{$wpdb->posts}` 1158 GROUP BY `menu_order`, `post_parent` 1159 HAVING COUNT( * ) >1 1160 )`b` 1161 ON `a`.`menu_order` = `b`.`menu_order` 1162 AND `a`.`post_parent` = `b`.`post_parent` 1163 WHERE `post_type` = '{$rpt}';", OBJECT_K ); 1164 1165 // Bail if no replies returned 1166 if ( empty( $replies ) ) { 1167 return array( 1, sprintf( $statement, $result ) ); 1168 } 1169 1170 // Recalculate the menu order position for each reply 1171 foreach ( $replies as $reply ) { 1172 bbp_update_reply_position( $reply->ID ); 1173 } 1174 1175 // Cleanup 1176 unset( $replies, $reply ); 1177 1178 // Flush the cache; things are about to get ugly. 1179 wp_cache_flush(); 1180 1110 1181 return array( 0, sprintf( $statement, __( 'Complete!', 'bbpress' ) ) ); 1111 1182 }
Note: See TracChangeset
for help on using the changeset viewer.