Skip to:
Content

bbPress.org

Changeset 4731


Ignore:
Timestamp:
01/28/2013 06:18:10 PM (12 years ago)
Author:
johnjamesjacoby
Message:

When repairing BuddyPress group forum relationships, also sync up the group forum status. Fixes #2089.

File:
1 edited

Legend:

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

    r4704 r4731  
    306306    $g_count     = 0;
    307307    $f_count     = 0;
     308    $s_count     = 0;
    308309
    309310    // Copy the BuddyPress filter here, incase BuddyPress is not active
    310     $prefix    = apply_filters( 'bp_core_get_table_prefix', $wpdb->base_prefix );
    311     $tablename = $prefix . 'bp_groups_groupmeta';
     311    $prefix            = apply_filters( 'bp_core_get_table_prefix', $wpdb->base_prefix );
     312    $groups_table      = $prefix . 'bp_groups';
     313    $groups_meta_table = $prefix . 'bp_groups_groupmeta';
    312314
    313315    // Get the converted forum IDs
     
    335337
    336338        // Attempt to update group meta
    337         $updated = $wpdb->query( "UPDATE `{$tablename}` SET `meta_value` = '{$group_forums->ID}' WHERE `meta_key` = 'forum_id' AND `meta_value` = '{$group_forums->meta_value}';" );
     339        $updated = $wpdb->query( "UPDATE `{$groups_meta_table}` SET `meta_value` = '{$group_forums->ID}' WHERE `meta_key` = 'forum_id' AND `meta_value` = '{$group_forums->meta_value}';" );
    338340
    339341        // Bump the count
     
    342344        }
    343345
    344         // Update group's forum metadata
    345         $group_id = (int) $wpdb->get_var( "SELECT `group_id` FROM `{$tablename}` WHERE `meta_key` = 'forum_id' AND `meta_value` = '{$group_forums->ID}';" );
     346        // Update group to forum relationship data
     347        $group_id = (int) $wpdb->get_var( "SELECT `group_id` FROM `{$groups_meta_table}` WHERE `meta_key` = 'forum_id' AND `meta_value` = '{$group_forums->ID}';" );
    346348        if ( !empty( $group_id ) ) {
     349
     350            // Update the group to forum meta connection in forums
    347351            update_post_meta( $group_forums->ID, '_bbp_group_ids', array( $group_id ) );
     352
     353            // Get the group status
     354            $group_status = $wpdb->get_var( "SELECT `status` FROM `{$groups_table}` WHERE `id` = '{$group_id}';" );
     355
     356            // Sync up forum visibility based on group status
     357            switch ( $group_status ) {
     358
     359                // Public groups have public forums
     360                case 'public' :
     361                    bbp_publicize_forum( $group_forums->ID );
     362
     363                    // Bump the count for output later
     364                    ++$s_count;
     365                    break;
     366
     367                // Private/hidden groups have hidden forums
     368                case 'private' :
     369                case 'hidden'  :
     370                    bbp_hide_forum( $group_forums->ID );
     371
     372                    // Bump the count for output later
     373                    ++$s_count;
     374                    break;
     375            }
     376
     377            // Bump the count for output later
    348378            ++$f_count;
    349379        }
     
    390420
    391421    // Complete results
    392     $result = sprintf( __( 'Complete! %s groups updated; %s forums updated.', 'bbpress' ), bbp_number_format( $g_count ), bbp_number_format( $f_count ) );
     422    $result = sprintf( __( 'Complete! %s groups updated; %s forums updated; %s forum statuses synced.', 'bbpress' ), bbp_number_format( $g_count ), bbp_number_format( $f_count ), bbp_number_format( $s_count ) );
    393423    return array( 0, sprintf( $statement, $result ) );
    394424}
Note: See TracChangeset for help on using the changeset viewer.