Skip to:
Content

bbPress.org

Ticket #2586: tools-repair.patch

File tools-repair.patch, 6.0 KB (added by netweb, 12 years ago)
  • src/includes/admin/tools.php

     
    288288                10 => array( 'bbp-sync-forum-visibility',    __( 'Recalculate private and hidden forums',             'bbpress' ), 'bbp_admin_repair_forum_visibility'         ),
    289289                15 => array( 'bbp-sync-all-topics-forums',   __( 'Recalculate last activity in each topic and forum', 'bbpress' ), 'bbp_admin_repair_freshness'                ),
    290290                20 => array( 'bbp-sync-all-topics-sticky',   __( 'Recalculate the sticky relationship of each topic', 'bbpress' ), 'bbp_admin_repair_sticky'                   ),
    291                 25 => array( 'bbp-group-forums',             __( 'Repair BuddyPress Group Forum relationships',       'bbpress' ), 'bbp_admin_repair_group_forum_relationship' ),
    292                 30 => array( 'bbp-forum-topics',             __( 'Count topics in each forum',                        'bbpress' ), 'bbp_admin_repair_forum_topic_count'        ),
    293                 35 => array( 'bbp-forum-replies',            __( 'Count replies in each forum',                       'bbpress' ), 'bbp_admin_repair_forum_reply_count'        ),
    294                 40 => array( 'bbp-topic-replies',            __( 'Count replies in each topic',                       'bbpress' ), 'bbp_admin_repair_topic_reply_count'        ),
    295                 45 => array( 'bbp-topic-voices',             __( 'Count voices in each topic',                        'bbpress' ), 'bbp_admin_repair_topic_voice_count'        ),
    296                 50 => array( 'bbp-topic-hidden-replies',     __( 'Count spammed & trashed replies in each topic',     'bbpress' ), 'bbp_admin_repair_topic_hidden_reply_count' ),
    297                 55 => array( 'bbp-user-topics',              __( 'Count topics for each user',                        'bbpress' ), 'bbp_admin_repair_user_topic_count'         ),
    298                 60 => array( 'bbp-user-replies',             __( 'Count replies for each user',                       'bbpress' ), 'bbp_admin_repair_user_reply_count'         ),
    299                 65 => array( 'bbp-user-favorites',           __( 'Remove trashed topics from user favorites',         'bbpress' ), 'bbp_admin_repair_user_favorites'           ),
    300                 70 => array( 'bbp-user-topic-subscriptions', __( 'Remove trashed topics from user subscriptions',     'bbpress' ), 'bbp_admin_repair_user_topic_subscriptions' ),
    301                 75 => array( 'bbp-user-forum-subscriptions', __( 'Remove trashed forums from user subscriptions',     'bbpress' ), 'bbp_admin_repair_user_forum_subscriptions' ),
    302                 80 => array( 'bbp-user-role-map',            __( 'Remap existing users to default forum roles',       'bbpress' ), 'bbp_admin_repair_user_roles'               )
     291                25 => array( 'bbp-sync-all-reply-positions', __( 'Recalculate the reply position of replies',         'bbpress' ), 'bbp_admin_repair_reply_menu_order'         ),
     292                30 => array( 'bbp-group-forums',             __( 'Repair BuddyPress Group Forum relationships',       'bbpress' ), 'bbp_admin_repair_group_forum_relationship' ),
     293                35 => array( 'bbp-forum-topics',             __( 'Count topics in each forum',                        'bbpress' ), 'bbp_admin_repair_forum_topic_count'        ),
     294                40 => array( 'bbp-forum-replies',            __( 'Count replies in each forum',                       'bbpress' ), 'bbp_admin_repair_forum_reply_count'        ),
     295                45 => array( 'bbp-topic-replies',            __( 'Count replies in each topic',                       'bbpress' ), 'bbp_admin_repair_topic_reply_count'        ),
     296                50 => array( 'bbp-topic-voices',             __( 'Count voices in each topic',                        'bbpress' ), 'bbp_admin_repair_topic_voice_count'        ),
     297                55 => array( 'bbp-topic-hidden-replies',     __( 'Count spammed & trashed replies in each topic',     'bbpress' ), 'bbp_admin_repair_topic_hidden_reply_count' ),
     298                60 => array( 'bbp-user-topics',              __( 'Count topics for each user',                        'bbpress' ), 'bbp_admin_repair_user_topic_count'         ),
     299                65 => array( 'bbp-user-replies',             __( 'Count replies for each user',                       'bbpress' ), 'bbp_admin_repair_user_reply_count'         ),
     300                70 => array( 'bbp-user-favorites',           __( 'Remove trashed topics from user favorites',         'bbpress' ), 'bbp_admin_repair_user_favorites'           ),
     301                75 => array( 'bbp-user-topic-subscriptions', __( 'Remove trashed topics from user subscriptions',     'bbpress' ), 'bbp_admin_repair_user_topic_subscriptions' ),
     302                80 => array( 'bbp-user-forum-subscriptions', __( 'Remove trashed forums from user subscriptions',     'bbpress' ), 'bbp_admin_repair_user_forum_subscriptions' ),
     303                85 => array( 'bbp-user-role-map',            __( 'Remap existing users to default forum roles',       'bbpress' ), 'bbp_admin_repair_user_roles'               )
    303304        );
    304305        ksort( $repair_list );
    305306
     
    11521189}
    11531190
    11541191/**
     1192 * Recalculate reply menu order
     1193 *
     1194 * @since bbPress (rXXXX)
     1195 *
     1196 * @uses wpdb::query() To run our recount sql queries
     1197 * @uses is_wp_error() To check if the executed query returned {@link WP_Error}
     1198 * @uses bbp_get_reply_post_type() To get the reply post type
     1199 * @uses bbp_update_reply_position() To update the reply position
     1200 * @return array An array of the status code and the message
     1201 */
     1202function bbp_admin_repair_reply_menu_order() {
     1203        global $wpdb;
     1204
     1205        $statement = __( 'Recalculating reply menuu order … %s', 'bbpress' );
     1206        $result    = __( 'Failed!', 'bbpress' );
     1207
     1208        // Post types and status
     1209        $rpt = bbp_get_reply_post_type();
     1210
     1211        // Get an array of reply id's to update the menu oder for each reply
     1212        $replies  = $wpdb->get_results( "SELECT `ID` FROM `{$wpdb->posts}` WHERE `post_type` = '{$rpt}';", OBJECT_K );
     1213
     1214        // Recalculate the menu order position for each reply
     1215        if ( ! empty( $replies ) ) {
     1216                foreach ( $replies as $reply ) {
     1217                        bbp_update_reply_position( $reply->ID );
     1218                }
     1219        } else {
     1220                return array( 1, sprintf( $statement, $result ) );
     1221        }
     1222
     1223        // Cleanup
     1224        unset( $replies, $reply );
     1225
     1226        return array( 0, sprintf( $statement, __( 'Complete!', 'bbpress' ) ) );
     1227}
     1228
     1229/**
    11551230 * Recaches the private and hidden forums
    11561231 *
    11571232 * @since bbPress (r4104)