Skip to:
Content

BuddyPress.org

Changeset 8589


Ignore:
Timestamp:
07/10/2014 10:22:16 PM (10 years ago)
Author:
johnjamesjacoby
Message:

Add return values to bp_blogs_record_existing_blogs() add use them in a new blog meta data recording repair tool. See #5749.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-blogs/bp-blogs-functions.php

    r8588 r8589  
    7979            $blog_ids = $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM {$wpdb->base_prefix}blogs WHERE mature = 0 AND spam = 0 AND deleted = 0 AND site_id = %d", $wpdb->siteid ) );
    8080
     81            // If error running this query, set blog ID's to false
     82            if ( is_wp_error( $blog_ids ) ) {
     83                $blog_ids = false;
     84            }
     85
    8186        // Large networks are not currently supported
    8287        } else {
     
    9196    // Bail if there are no blogs in the network
    9297    if ( empty( $blog_ids ) ) {
    93         return;
    94     }
    95 
    96     // Truncate user blogs table and re-record.
    97     $wpdb->query( "TRUNCATE {$bp->blogs->table_name}"          );
    98     $wpdb->query( "TRUNCATE {$bp->blogs->table_name_blogmeta}" );
     98        return false;
     99    }
     100
     101    // Truncate user blogs table
     102    $truncate = $wpdb->query( "TRUNCATE {$bp->blogs->table_name}" );
     103    if ( is_wp_error( $truncate ) ) {
     104        return false;
     105    }
     106
     107    // Truncate user blogsmeta table
     108    $truncate = $wpdb->query( "TRUNCATE {$bp->blogs->table_name_blogmeta}" );
     109    if ( is_wp_error( $truncate ) ) {
     110        return false;
     111    }
    99112
    100113    // Loop through users of blogs and record the relationship
     
    130143        }
    131144    }
     145
     146    // No errors
     147    return true;
    132148}
    133149
  • trunk/src/bp-core/admin/bp-core-tools.php

    r8146 r8589  
    133133    }
    134134
     135    // Blogs:
     136    // - user blog count
     137    if ( bp_is_active( 'blogs' ) ) {
     138        $repair_list[90] = array(
     139            'bp-blog-records',
     140            __( 'Repopulate blogs records', 'buddypress' ),
     141            'bp_admin_repair_blog_records',
     142        );
     143    }
     144
    135145    ksort( $repair_list );
    136146
     
    240250
    241251/**
     252 * Recalculate user-to-blog relationships and useful blog meta data
     253 *
     254 * @since BuddyPress (2.1.0)
     255 *
     256 * @return array
     257 */
     258function bp_admin_repair_blog_records() {
     259
     260    // Description of this tool, dispalyed to the user
     261    $statement = __( 'Repopulating Blogs records… %s', 'buddypress' );
     262
     263    // Default to failure text
     264    $result    = __( 'Failed!',   'buddypress' );
     265
     266    // Default to unrepaired
     267    $repair    = false;
     268
     269    // Run function if blogs component is active
     270    if ( bp_is_active( 'blogs' ) ) {
     271        $repair = bp_blogs_record_existing_blogs();
     272    }
     273
     274    // Setup success/fail messaging
     275    if ( true === $repair ) {
     276        $result = __( 'Complete!', 'buddypress' );
     277    }
     278
     279    // All done!
     280    return array( 0, sprintf( $statement, $result ) );
     281}
     282
     283/**
    242284 * Recalculate the total number of active site members.
    243285 *
     
    282324            case 0:
    283325                return false;
    284                 break;
    285326
    286327            case 1:
Note: See TracChangeset for help on using the changeset viewer.