Skip to:
Content

bbPress.org

Changeset 5253


Ignore:
Timestamp:
01/12/2014 05:42:02 AM (11 years ago)
Author:
netweb
Message:

Remove hard coded post type references in repair tools. Props thebrandonallen. Fixes #2510

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/admin/tools.php

    r5175 r5253  
    187187 * @since bbPress (r2613)
    188188 *
    189  * @uses bbp_get_reply_post_type() To get the reply post type
    190189 * @uses wpdb::query() To run our recount sql queries
    191190 * @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
    192195 * @return array An array of the status code and the message
    193196 */
     
    230233 * @since bbPress (r2613)
    231234 *
    232  * @uses bbp_get_reply_post_type() To get the reply post type
    233235 * @uses wpdb::query() To run our recount sql queries
    234236 * @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
    235241 * @return array An array of the status code and the message
    236242 */
     
    275281 * @uses wpdb::query() To run our recount sql queries
    276282 * @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
    277286 * @return array An array of the status code and the message
    278287 */
     
    287296        return array( 1, sprintf( $statement, $result ) );
    288297
    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`);";
    290304    if ( is_wp_error( $wpdb->query( $sql ) ) )
    291305        return array( 2, sprintf( $statement, $result ) );
     
    300314 *
    301315 * @global WPDB $wpdb
     316 * @uses bbp_get_forum_post_type() To get the forum post type
    302317 * @return If a wp_error() occurs and no converted forums are found
    303318 */
     
    321336                                        ON `forum`.`ID` = `forummeta`.`post_id`
    322337                                        AND `forummeta`.`meta_key` = '_bbp_old_forum_id'
    323                                 WHERE `forum`.`post_type` = 'forum'
     338                                WHERE `forum`.`post_type` = '" . bbp_get_forum_post_type() . "'
    324339                                GROUP BY `forum`.`ID`;" );
    325340
     
    500515 * @since bbPress (r3889)
    501516 *
    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
    503519 * @uses wpdb::query() To run our recount sql queries
    504520 * @uses is_wp_error() To check if the executed query returned {@link WP_Error}
     
    546562 *
    547563 * @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
    548565 * @uses wpdb::query() To run our recount sql queries
    549566 * @uses is_wp_error() To check if the executed query returned {@link WP_Error}
     
    590607 * @since bbPress (r2613)
    591608 *
    592  * @uses bbp_get_topic_post_type() To get the topic post type
    593609 * @uses wpdb::query() To run our recount sql queries
    594610 * @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
    595613 * @return array An array of the status code and the message
    596614 */
     
    652670 * @since bbPress (r2668)
    653671 *
    654  * @uses bbp_get_topic_post_type() To get the topic post type
    655672 * @uses wpdb::query() To run our recount sql queries
    656673 * @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
    657676 * @return array An array of the status code and the message
    658677 */
     
    713732 * @since bbPress (r5155)
    714733 *
    715  * @uses bbp_get_forum_post_type() To get the topic post type
    716734 * @uses wpdb::query() To run our recount sql queries
    717735 * @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
    718738 * @return array An array of the status code and the message
    719739 */
     
    777797 *
    778798 * @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
    780801 * @uses get_users() To get the users of each role (limited to ID field)
    781802 * @uses bbp_set_user_role() To set each user's forums role
     
    832853 * @uses wpdb::query() To run our recount sql queries
    833854 * @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
    834861 * @return array An array of the status code and the message
    835862 */
     
    843870    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' );" ) ) )
    844871        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();
    845878
    846879    // Next, give all the topics with replies the ID their last reply.
     
    848881            ( SELECT `topic`.`ID`, '_bbp_last_reply_id', MAX( `reply`.`ID` )
    849882            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}'
    851884            GROUP BY `topic`.`ID` );" ) ) )
    852885        return array( 2, sprintf( $statement, $result ) );
     
    857890            FROM `$wpdb->posts` AS `topic` LEFT JOIN `$wpdb->postmeta` AS `reply`
    858891            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}' );" ) ) )
    860893        return array( 3, sprintf( $statement, $result ) );
    861894
     
    864897            ( SELECT `forum`.`ID`, '_bbp_last_topic_id', `topic`.`ID`
    865898            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}'
    867900            GROUP BY `forum`.`ID` );" ) ) )
    868901        return array( 4, sprintf( $statement, $result ) );
     
    873906            FROM `$wpdb->posts` AS `forum` LEFT JOIN `$wpdb->postmeta` AS `topic`
    874907            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}' );" ) ) )
    876909        return array( 5, sprintf( $statement, $result ) );
    877910
     
    880913            ( SELECT `topic`.`ID`, '_bbp_last_active_id', MAX( `reply`.`ID` )
    881914            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}'
    883916            GROUP BY `topic`.`ID` );" ) ) )
    884917        return array( 6, sprintf( $statement, $result ) );
     
    889922            FROM `$wpdb->posts` AS `topic` LEFT JOIN `$wpdb->postmeta` AS `reply`
    890923            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}' );" ) ) )
    892925        return array( 7, sprintf( $statement, $result ) );
    893926
     
    896929            ( SELECT `topic`.`ID`, '_bbp_last_active_time', MAX( `reply`.`post_date` )
    897930            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}'
    899932            GROUP BY `topic`.`ID` );" ) ) )
    900933        return array( 8, sprintf( $statement, $result ) );
     
    905938            FROM `$wpdb->posts` AS `topic` LEFT JOIN `$wpdb->postmeta` AS `reply`
    906939            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}' );" ) ) )
    908941        return array( 9, sprintf( $statement, $result ) );
    909942
    910943    // 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';" );
    912945    if ( is_wp_error( $forums ) )
    913946        return array( 10, sprintf( $statement, $result ) );
     
    938971 * @uses wpdb::get_col() To run our recount sql queries
    939972 * @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
    940978 * @return array An array of the status code and the message
    941979 */
     
    945983    $statement = __( 'Repairing the sticky topic to the parent forum relationships… %s', 'bbpress' );
    946984    $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() . "';" );
    948986
    949987    // Bail if no forums found
     
    9931031 * @since bbPress (r4104)
    9941032 *
    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
    9991034 * @return array An array of the status code and the message
    10001035 */
     
    10191054 * @uses wpdb::query() To run our recount sql queries
    10201055 * @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
    10211059 * @return array An array of the status code and the message
    10221060 */
     
    10301068    if ( is_wp_error( $wpdb->query( "DELETE FROM `$wpdb->postmeta` WHERE `meta_key` = '_bbp_forum_id';" ) ) )
    10311069        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();
    10321075
    10331076    // Next, give all the topics with replies the ID their last reply.
     
    10361079            FROM `$wpdb->posts`
    10371080                AS `forum`
    1038             WHERE `forum`.`post_type` = 'forum'
     1081            WHERE `forum`.`post_type` = '{$fpt}'
    10391082            GROUP BY `forum`.`ID` );" ) ) )
    10401083        return array( 2, sprintf( $statement, $result ) );
     
    10451088            FROM `$wpdb->posts`
    10461089                AS `topic`
    1047             WHERE `topic`.`post_type` = 'topic'
     1090            WHERE `topic`.`post_type` = '{$tpt}'
    10481091            GROUP BY `topic`.`ID` );" ) ) )
    10491092        return array( 3, sprintf( $statement, $result ) );
     
    10571100                AS `topic`
    10581101                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}'
    10611104            GROUP BY `reply`.`ID` );" ) ) )
    10621105        return array( 4, sprintf( $statement, $result ) );
     
    10731116 * @uses wpdb::query() To run our recount sql queries
    10741117 * @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
    10751120 * @return array An array of the status code and the message
    10761121 */
     
    10841129    if ( is_wp_error( $wpdb->query( "DELETE FROM `$wpdb->postmeta` WHERE `meta_key` = '_bbp_topic_id';" ) ) )
    10851130        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();
    10861135
    10871136    // Next, give all the topics with replies the ID their last reply.
     
    10901139            FROM `$wpdb->posts`
    10911140                AS `topic`
    1092             WHERE `topic`.`post_type` = 'topic'
     1141            WHERE `topic`.`post_type` = '{$tpt}'
    10931142            GROUP BY `topic`.`ID` );" ) ) )
    10941143        return array( 3, sprintf( $statement, $result ) );
     
    11021151                AS `topic`
    11031152                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}'
    11061155            GROUP BY `reply`.`ID` );" ) ) )
    11071156        return array( 4, sprintf( $statement, $result ) );
     
    11911240 * @uses check_admin_referer() To verify the nonce and the referer
    11921241 * @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
    11931245 */
    11941246function bbp_admin_reset_handler() {
     
    12161268    /** Posts *****************************************************************/
    12171269
     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
    12181275    $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}')";
    12211278    $result     = is_wp_error( $wpdb->query( $sql_delete ) ) ? $failed : $success;
    12221279    $messages[] = sprintf( $statement, $result );
Note: See TracChangeset for help on using the changeset viewer.