Changeset 5253
- Timestamp:
- 01/12/2014 05:42:02 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/includes/admin/tools.php
r5175 r5253 187 187 * @since bbPress (r2613) 188 188 * 189 * @uses bbp_get_reply_post_type() To get the reply post type190 189 * @uses wpdb::query() To run our recount sql queries 191 190 * @uses is_wp_error() To check if the executed query returned {@link WP_Error} 191 * @uses bbp_get_topic_post_type() To get the topic post type 192 * @uses bbp_get_reply_post_type() To get the reply post type 193 * @uses bbp_get_public_status_id() To get the public status id 194 * @uses bbp_get_closed_status_id() To get the closed status id 192 195 * @return array An array of the status code and the message 193 196 */ … … 230 233 * @since bbPress (r2613) 231 234 * 232 * @uses bbp_get_reply_post_type() To get the reply post type233 235 * @uses wpdb::query() To run our recount sql queries 234 236 * @uses is_wp_error() To check if the executed query returned {@link WP_Error} 237 * @uses bbp_get_topic_post_type() To get the topic post type 238 * @uses bbp_get_reply_post_type() To get the reply post type 239 * @uses bbp_get_public_status_id() To get the public status id 240 * @uses bbp_get_closed_status_id() To get the closed status id 235 241 * @return array An array of the status code and the message 236 242 */ … … 275 281 * @uses wpdb::query() To run our recount sql queries 276 282 * @uses is_wp_error() To check if the executed query returned {@link WP_Error} 283 * @uses bbp_get_reply_post_type() To get the reply post type 284 * @uses bbp_get_trash_status_id() To get the trash status id 285 * @uses bbp_get_spam_status_id() To get the spam status id 277 286 * @return array An array of the status code and the message 278 287 */ … … 287 296 return array( 1, sprintf( $statement, $result ) ); 288 297 289 $sql = "INSERT INTO `{$wpdb->postmeta}` (`post_id`, `meta_key`, `meta_value`) (SELECT `post_parent`, '_bbp_reply_count_hidden', COUNT(`post_status`) as `meta_value` FROM `{$wpdb->posts}` WHERE `post_type` = '" . bbp_get_reply_post_type() . "' AND `post_status` IN ( '" . implode( "','", array( bbp_get_trash_status_id(), bbp_get_spam_status_id() ) ) . "') GROUP BY `post_parent`);"; 298 // Post types and status 299 $rpt = bbp_get_reply_post_type(); 300 $tps = bbp_get_trash_status_id(); 301 $sps = bbp_get_spam_status_id(); 302 303 $sql = "INSERT INTO `{$wpdb->postmeta}` (`post_id`, `meta_key`, `meta_value`) (SELECT `post_parent`, '_bbp_reply_count_hidden', COUNT(`post_status`) as `meta_value` FROM `{$wpdb->posts}` WHERE `post_type` = '{$rpt}' AND `post_status` IN ( '{$tps}', '{$sps}' ) GROUP BY `post_parent`);"; 290 304 if ( is_wp_error( $wpdb->query( $sql ) ) ) 291 305 return array( 2, sprintf( $statement, $result ) ); … … 300 314 * 301 315 * @global WPDB $wpdb 316 * @uses bbp_get_forum_post_type() To get the forum post type 302 317 * @return If a wp_error() occurs and no converted forums are found 303 318 */ … … 321 336 ON `forum`.`ID` = `forummeta`.`post_id` 322 337 AND `forummeta`.`meta_key` = '_bbp_old_forum_id' 323 WHERE `forum`.`post_type` = ' forum'338 WHERE `forum`.`post_type` = '" . bbp_get_forum_post_type() . "' 324 339 GROUP BY `forum`.`ID`;" ); 325 340 … … 500 515 * @since bbPress (r3889) 501 516 * 502 * @uses bbp_get_reply_post_type() To get the reply post type 517 * @uses bbp_get_topic_post_type() To get the topic post type 518 * @uses bbp_get_public_status_id() To get the public status id 503 519 * @uses wpdb::query() To run our recount sql queries 504 520 * @uses is_wp_error() To check if the executed query returned {@link WP_Error} … … 546 562 * 547 563 * @uses bbp_get_reply_post_type() To get the reply post type 564 * @uses bbp_get_public_status_id() To get the public status id 548 565 * @uses wpdb::query() To run our recount sql queries 549 566 * @uses is_wp_error() To check if the executed query returned {@link WP_Error} … … 590 607 * @since bbPress (r2613) 591 608 * 592 * @uses bbp_get_topic_post_type() To get the topic post type593 609 * @uses wpdb::query() To run our recount sql queries 594 610 * @uses is_wp_error() To check if the executed query returned {@link WP_Error} 611 * @uses bbp_get_topic_post_type() To get the topic post type 612 * @uses bbp_get_public_status_id() To get the public status id 595 613 * @return array An array of the status code and the message 596 614 */ … … 652 670 * @since bbPress (r2668) 653 671 * 654 * @uses bbp_get_topic_post_type() To get the topic post type655 672 * @uses wpdb::query() To run our recount sql queries 656 673 * @uses is_wp_error() To check if the executed query returned {@link WP_Error} 674 * @uses bbp_get_topic_post_type() To get the topic post type 675 * @uses bbp_get_public_status_id() To get the public status id 657 676 * @return array An array of the status code and the message 658 677 */ … … 713 732 * @since bbPress (r5155) 714 733 * 715 * @uses bbp_get_forum_post_type() To get the topic post type716 734 * @uses wpdb::query() To run our recount sql queries 717 735 * @uses is_wp_error() To check if the executed query returned {@link WP_Error} 736 * @uses bbp_get_forum_post_type() To get the forum post type 737 * @uses bbp_get_public_status_id() To get the public status id 718 738 * @return array An array of the status code and the message 719 739 */ … … 777 797 * 778 798 * @uses bbp_get_user_role_map() To get the map of user roles 779 * @uses get_editable_roles() To get the current WordPress roles 799 * @uses bbp_get_default_role() To get the default bbPress user role 800 * @uses bbp_get_blog_roles() To get the current WordPress roles 780 801 * @uses get_users() To get the users of each role (limited to ID field) 781 802 * @uses bbp_set_user_role() To set each user's forums role … … 832 853 * @uses wpdb::query() To run our recount sql queries 833 854 * @uses is_wp_error() To check if the executed query returned {@link WP_Error} 855 * @uses bbp_get_forum_post_type() To get the forum post type 856 * @uses bbp_get_topic_post_type() To get the topic post type 857 * @uses bbp_get_reply_post_type() To get the reply post type 858 * @uses bbp_get_public_status_id() To get the public status id 859 * @uses bbp_is_forum_category() To check if the forum is a ategory 860 * @uses bbp_update_forum() To update the forums forum id 834 861 * @return array An array of the status code and the message 835 862 */ … … 843 870 if ( is_wp_error( $wpdb->query( "DELETE FROM `$wpdb->postmeta` WHERE `meta_key` IN ( '_bbp_last_reply_id', '_bbp_last_topic_id', '_bbp_last_active_id', '_bbp_last_active_time' );" ) ) ) 844 871 return array( 1, sprintf( $statement, $result ) ); 872 873 // Post types and status 874 $fpt = bbp_get_forum_post_type(); 875 $tpt = bbp_get_topic_post_type(); 876 $rpt = bbp_get_reply_post_type(); 877 $pps = bbp_get_public_status_id(); 845 878 846 879 // Next, give all the topics with replies the ID their last reply. … … 848 881 ( SELECT `topic`.`ID`, '_bbp_last_reply_id', MAX( `reply`.`ID` ) 849 882 FROM `$wpdb->posts` AS `topic` INNER JOIN `$wpdb->posts` AS `reply` ON `topic`.`ID` = `reply`.`post_parent` 850 WHERE `reply`.`post_status` IN ( '" . bbp_get_public_status_id() . "' ) AND `topic`.`post_type` = 'topic' AND `reply`.`post_type` = 'reply'883 WHERE `reply`.`post_status` = '{$pps}' AND `topic`.`post_type` = '{$tpt}' AND `reply`.`post_type` = '{$rpt}' 851 884 GROUP BY `topic`.`ID` );" ) ) ) 852 885 return array( 2, sprintf( $statement, $result ) ); … … 857 890 FROM `$wpdb->posts` AS `topic` LEFT JOIN `$wpdb->postmeta` AS `reply` 858 891 ON `topic`.`ID` = `reply`.`post_id` AND `reply`.`meta_key` = '_bbp_last_reply_id' 859 WHERE `reply`.`meta_id` IS NULL AND `topic`.`post_type` = ' topic' );" ) ) )892 WHERE `reply`.`meta_id` IS NULL AND `topic`.`post_type` = '{$tpt}' );" ) ) ) 860 893 return array( 3, sprintf( $statement, $result ) ); 861 894 … … 864 897 ( SELECT `forum`.`ID`, '_bbp_last_topic_id', `topic`.`ID` 865 898 FROM `$wpdb->posts` AS `forum` INNER JOIN `$wpdb->posts` AS `topic` ON `forum`.`ID` = `topic`.`post_parent` 866 WHERE `topic`.`post_status` IN ( '" . bbp_get_public_status_id() . "' ) AND `forum`.`post_type` = 'forum' AND `topic`.`post_type` = 'topic'899 WHERE `topic`.`post_status` = '{$pps}' AND `forum`.`post_type` = '{$fpt}' AND `topic`.`post_type` = '{$tpt}' 867 900 GROUP BY `forum`.`ID` );" ) ) ) 868 901 return array( 4, sprintf( $statement, $result ) ); … … 873 906 FROM `$wpdb->posts` AS `forum` LEFT JOIN `$wpdb->postmeta` AS `topic` 874 907 ON `forum`.`ID` = `topic`.`post_id` AND `topic`.`meta_key` = '_bbp_last_topic_id' 875 WHERE `topic`.`meta_id` IS NULL AND `forum`.`post_type` = ' forum' );" ) ) )908 WHERE `topic`.`meta_id` IS NULL AND `forum`.`post_type` = '{$fpt}' );" ) ) ) 876 909 return array( 5, sprintf( $statement, $result ) ); 877 910 … … 880 913 ( SELECT `topic`.`ID`, '_bbp_last_active_id', MAX( `reply`.`ID` ) 881 914 FROM `$wpdb->posts` AS `topic` INNER JOIN `$wpdb->posts` AS `reply` ON `topic`.`ID` = `reply`.`post_parent` 882 WHERE `reply`.`post_status` IN ( '" . bbp_get_public_status_id() . "' ) AND `topic`.`post_type` = 'topic' AND `reply`.`post_type` = 'reply'915 WHERE `reply`.`post_status` = '{$pps}' AND `topic`.`post_type` = '{$tpt}' AND `reply`.`post_type` = '{$rpt}' 883 916 GROUP BY `topic`.`ID` );" ) ) ) 884 917 return array( 6, sprintf( $statement, $result ) ); … … 889 922 FROM `$wpdb->posts` AS `topic` LEFT JOIN `$wpdb->postmeta` AS `reply` 890 923 ON `topic`.`ID` = `reply`.`post_id` AND `reply`.`meta_key` = '_bbp_last_active_id' 891 WHERE `reply`.`meta_id` IS NULL AND `topic`.`post_type` = ' topic' );" ) ) )924 WHERE `reply`.`meta_id` IS NULL AND `topic`.`post_type` = '{$tpt}' );" ) ) ) 892 925 return array( 7, sprintf( $statement, $result ) ); 893 926 … … 896 929 ( SELECT `topic`.`ID`, '_bbp_last_active_time', MAX( `reply`.`post_date` ) 897 930 FROM `$wpdb->posts` AS `topic` INNER JOIN `$wpdb->posts` AS `reply` ON `topic`.`ID` = `reply`.`post_parent` 898 WHERE `reply`.`post_status` IN ( '" . bbp_get_public_status_id() . "' ) AND `topic`.`post_type` = 'topic' AND `reply`.`post_type` = 'reply'931 WHERE `reply`.`post_status` = '{$pps}' AND `topic`.`post_type` = '{$tpt}' AND `reply`.`post_type` = '{$rpt}' 899 932 GROUP BY `topic`.`ID` );" ) ) ) 900 933 return array( 8, sprintf( $statement, $result ) ); … … 905 938 FROM `$wpdb->posts` AS `topic` LEFT JOIN `$wpdb->postmeta` AS `reply` 906 939 ON `topic`.`ID` = `reply`.`post_id` AND `reply`.`meta_key` = '_bbp_last_active_time' 907 WHERE `reply`.`meta_id` IS NULL AND `topic`.`post_type` = ' topic' );" ) ) )940 WHERE `reply`.`meta_id` IS NULL AND `topic`.`post_type` = '{$tpt}' );" ) ) ) 908 941 return array( 9, sprintf( $statement, $result ) ); 909 942 910 943 // Forums need to know what their last active item is as well. Now it gets a bit more complex to do in the database. 911 $forums = $wpdb->get_col( "SELECT `ID` FROM `$wpdb->posts` WHERE `post_type` = ' forum' and `post_status` != 'auto-draft';" );944 $forums = $wpdb->get_col( "SELECT `ID` FROM `$wpdb->posts` WHERE `post_type` = '{$fpt}' and `post_status` != 'auto-draft';" ); 912 945 if ( is_wp_error( $forums ) ) 913 946 return array( 10, sprintf( $statement, $result ) ); … … 938 971 * @uses wpdb::get_col() To run our recount sql queries 939 972 * @uses is_wp_error() To check if the executed query returned {@link WP_Error} 973 * @uses bbp_get_forum_post_type() To get the forum post type 974 * @uses get_post_meta() To get the sticky topics 975 * @uses bbp_is_topic_super_sticky() To check if the topic is super sticky 976 * @uses bbp_get_topic_forum_id() To get the topics forum id 977 * @uses update_post_meta To update the topics sticky post meta 940 978 * @return array An array of the status code and the message 941 979 */ … … 945 983 $statement = __( 'Repairing the sticky topic to the parent forum relationships… %s', 'bbpress' ); 946 984 $result = __( 'Failed!', 'bbpress' ); 947 $forums = $wpdb->get_col( "SELECT ID FROM `{$wpdb->posts}` WHERE `post_type` = ' forum';" );985 $forums = $wpdb->get_col( "SELECT ID FROM `{$wpdb->posts}` WHERE `post_type` = '" . bbp_get_forum_post_type() . "';" ); 948 986 949 987 // Bail if no forums found … … 993 1031 * @since bbPress (r4104) 994 1032 * 995 * @uses delete_option() to delete private and hidden forum pointers 996 * @uses WP_Query() To query post IDs 997 * @uses is_wp_error() To return if error occurred 998 * @uses update_option() To update the private and hidden post ID pointers 1033 * @uses bbp_repair_forum_visibility() To update private and hidden forum ids 999 1034 * @return array An array of the status code and the message 1000 1035 */ … … 1019 1054 * @uses wpdb::query() To run our recount sql queries 1020 1055 * @uses is_wp_error() To check if the executed query returned {@link WP_Error} 1056 * @uses bbp_get_forum_post_type() To get the forum post type 1057 * @uses bbp_get_topic_post_type() To get the topic post type 1058 * @uses bbp_get_reply_post_type() To get the reply post type 1021 1059 * @return array An array of the status code and the message 1022 1060 */ … … 1030 1068 if ( is_wp_error( $wpdb->query( "DELETE FROM `$wpdb->postmeta` WHERE `meta_key` = '_bbp_forum_id';" ) ) ) 1031 1069 return array( 1, sprintf( $statement, $result ) ); 1070 1071 // Post types and status 1072 $fpt = bbp_get_forum_post_type(); 1073 $tpt = bbp_get_topic_post_type(); 1074 $rpt = bbp_get_reply_post_type(); 1032 1075 1033 1076 // Next, give all the topics with replies the ID their last reply. … … 1036 1079 FROM `$wpdb->posts` 1037 1080 AS `forum` 1038 WHERE `forum`.`post_type` = ' forum'1081 WHERE `forum`.`post_type` = '{$fpt}' 1039 1082 GROUP BY `forum`.`ID` );" ) ) ) 1040 1083 return array( 2, sprintf( $statement, $result ) ); … … 1045 1088 FROM `$wpdb->posts` 1046 1089 AS `topic` 1047 WHERE `topic`.`post_type` = ' topic'1090 WHERE `topic`.`post_type` = '{$tpt}' 1048 1091 GROUP BY `topic`.`ID` );" ) ) ) 1049 1092 return array( 3, sprintf( $statement, $result ) ); … … 1057 1100 AS `topic` 1058 1101 ON `reply`.`post_parent` = `topic`.`ID` 1059 WHERE `topic`.`post_type` = ' topic'1060 AND `reply`.`post_type` = ' reply'1102 WHERE `topic`.`post_type` = '{$tpt}' 1103 AND `reply`.`post_type` = '{$rpt}' 1061 1104 GROUP BY `reply`.`ID` );" ) ) ) 1062 1105 return array( 4, sprintf( $statement, $result ) ); … … 1073 1116 * @uses wpdb::query() To run our recount sql queries 1074 1117 * @uses is_wp_error() To check if the executed query returned {@link WP_Error} 1118 * @uses bbp_get_topic_post_type() To get the topic post type 1119 * @uses bbp_get_reply_post_type() To get the reply post type 1075 1120 * @return array An array of the status code and the message 1076 1121 */ … … 1084 1129 if ( is_wp_error( $wpdb->query( "DELETE FROM `$wpdb->postmeta` WHERE `meta_key` = '_bbp_topic_id';" ) ) ) 1085 1130 return array( 1, sprintf( $statement, $result ) ); 1131 1132 // Post types and status 1133 $tpt = bbp_get_topic_post_type(); 1134 $rpt = bbp_get_reply_post_type(); 1086 1135 1087 1136 // Next, give all the topics with replies the ID their last reply. … … 1090 1139 FROM `$wpdb->posts` 1091 1140 AS `topic` 1092 WHERE `topic`.`post_type` = ' topic'1141 WHERE `topic`.`post_type` = '{$tpt}' 1093 1142 GROUP BY `topic`.`ID` );" ) ) ) 1094 1143 return array( 3, sprintf( $statement, $result ) ); … … 1102 1151 AS `topic` 1103 1152 ON `reply`.`post_parent` = `topic`.`ID` 1104 WHERE `topic`.`post_type` = ' topic'1105 AND `reply`.`post_type` = ' reply'1153 WHERE `topic`.`post_type` = '{$tpt}' 1154 AND `reply`.`post_type` = '{$rpt}' 1106 1155 GROUP BY `reply`.`ID` );" ) ) ) 1107 1156 return array( 4, sprintf( $statement, $result ) ); … … 1191 1240 * @uses check_admin_referer() To verify the nonce and the referer 1192 1241 * @uses wp_cache_flush() To flush the cache 1242 * @uses bbp_get_forum_post_type() To get the forum post type 1243 * @uses bbp_get_topic_post_type() To get the topic post type 1244 * @uses bbp_get_reply_post_type() To get the reply post type 1193 1245 */ 1194 1246 function bbp_admin_reset_handler() { … … 1216 1268 /** Posts *****************************************************************/ 1217 1269 1270 // Post types and status 1271 $fpt = bbp_get_forum_post_type(); 1272 $tpt = bbp_get_topic_post_type(); 1273 $rpt = bbp_get_reply_post_type(); 1274 1218 1275 $statement = __( 'Deleting Posts… %s', 'bbpress' ); 1219 $sql_posts = $wpdb->get_results( "SELECT `ID` FROM `{$wpdb->posts}` WHERE `post_type` IN (' forum', 'topic', 'reply')", OBJECT_K );1220 $sql_delete = "DELETE FROM `{$wpdb->posts}` WHERE `post_type` IN (' forum', 'topic', 'reply')";1276 $sql_posts = $wpdb->get_results( "SELECT `ID` FROM `{$wpdb->posts}` WHERE `post_type` IN ('{$fpt}', '{$tpt}', '{$rpt}')", OBJECT_K ); 1277 $sql_delete = "DELETE FROM `{$wpdb->posts}` WHERE `post_type` IN ('{$fpt}', '{$tpt}', '{$rpt}')"; 1221 1278 $result = is_wp_error( $wpdb->query( $sql_delete ) ) ? $failed : $success; 1222 1279 $messages[] = sprintf( $statement, $result );
Note: See TracChangeset
for help on using the changeset viewer.