WordPress.org

Make WordPress Core

Changeset 19038


Ignore:
Timestamp:
10/21/2011 10:04:52 PM (7 years ago)
Author:
nacin
Message:

Make wpmu_delete_blog() slightly less crappy. Prevents the entire network from being dropped in a particularly rare edge case. Removes some zombie code. fixes #19009.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/ms.php

    r18871 r19038  
    5454 */
    5555function wpmu_delete_blog( $blog_id, $drop = false ) {
    56     global $wpdb;
     56    global $wpdb, $current_site;
    5757
    5858    $switch = false;
     
    6060        $switch = true;
    6161        switch_to_blog( $blog_id );
    62     }
    63 
    64     $blog_prefix = $wpdb->get_blog_prefix( $blog_id );
     62        $blog = get_blog_details( $blog_id );
     63    } else {
     64        $blog = $GLOBALS['current_blog'];
     65    }
    6566
    6667    do_action( 'delete_blog', $blog_id, $drop );
     
    7172    if ( ! empty( $users ) ) {
    7273        foreach ( $users as $user_id ) {
    73             remove_user_from_blog( $user_id, $blog_id) ;
     74            remove_user_from_blog( $user_id, $blog_id );
    7475        }
    7576    }
     
    7778    update_blog_status( $blog_id, 'deleted', 1 );
    7879
     80    // Don't destroy the initial, main, or root blog.
     81    if ( $drop && ( 1 == $blog_id || is_main_site( $blog_id ) || ( $blog->path == $current_site->path && $blog->domain == $current_site->domain ) ) )
     82        $drop = false;
     83
    7984    if ( $drop ) {
    80         if ( substr( $blog_prefix, -1 ) == '_' )
    81             $blog_prefix =  substr( $blog_prefix, 0, -1 ) . '\_';
    82 
    83         $drop_tables = $wpdb->get_results( "SHOW TABLES LIKE '{$blog_prefix}%'", ARRAY_A );
    84         $drop_tables = apply_filters( 'wpmu_drop_tables', $drop_tables );
    85 
    86         reset( $drop_tables );
    87         foreach ( (array) $drop_tables as $drop_table) {
    88             $wpdb->query( "DROP TABLE IF EXISTS ". current( $drop_table ) ."" );
    89         }
     85
     86        $drop_tables = apply_filters( 'wpmu_drop_tables', $wpdb->tables( 'blog' ) );
     87
     88        foreach ( (array) $drop_tables as $table ) {
     89            $wpdb->query( "DROP TABLE IF EXISTS `$table`" );
     90        }
     91
    9092        $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->blogs WHERE blog_id = %d", $blog_id ) );
    9193        $dir = apply_filters( 'wpmu_delete_blog_upload_dir', WP_CONTENT_DIR . "/blogs.dir/{$blog_id}/files/", $blog_id );
     
    121123    }
    122124
    123     $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key = '{$blog_prefix}autosave_draft_ids'" );
    124     $blogs = get_site_option( 'blog_list' );
    125     if ( is_array( $blogs ) ) {
    126         foreach ( $blogs as $n => $blog ) {
    127             if ( $blog['blog_id'] == $blog_id )
    128                 unset( $blogs[$n] );
    129         }
    130         update_site_option( 'blog_list', $blogs );
    131     }
    132 
    133     if ( $switch === true )
     125    if ( $switch )
    134126        restore_current_blog();
    135127}
Note: See TracChangeset for help on using the changeset viewer.