mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-23 01:27:36 +01:00
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.
git-svn-id: http://svn.automattic.com/wordpress/trunk@19038 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
975c670f15
commit
f708c5eaff
@ -53,16 +53,17 @@ add_filter( 'wp_handle_upload_prefilter', 'check_upload_size' );
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function wpmu_delete_blog( $blog_id, $drop = false ) {
|
function wpmu_delete_blog( $blog_id, $drop = false ) {
|
||||||
global $wpdb;
|
global $wpdb, $current_site;
|
||||||
|
|
||||||
$switch = false;
|
$switch = false;
|
||||||
if ( $blog_id != $wpdb->blogid ) {
|
if ( $blog_id != $wpdb->blogid ) {
|
||||||
$switch = true;
|
$switch = true;
|
||||||
switch_to_blog( $blog_id );
|
switch_to_blog( $blog_id );
|
||||||
|
$blog = get_blog_details( $blog_id );
|
||||||
|
} else {
|
||||||
|
$blog = $GLOBALS['current_blog'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$blog_prefix = $wpdb->get_blog_prefix( $blog_id );
|
|
||||||
|
|
||||||
do_action( 'delete_blog', $blog_id, $drop );
|
do_action( 'delete_blog', $blog_id, $drop );
|
||||||
|
|
||||||
$users = get_users( array( 'blog_id' => $blog_id, 'fields' => 'ids' ) );
|
$users = get_users( array( 'blog_id' => $blog_id, 'fields' => 'ids' ) );
|
||||||
@ -70,23 +71,24 @@ function wpmu_delete_blog( $blog_id, $drop = false ) {
|
|||||||
// Remove users from this blog.
|
// Remove users from this blog.
|
||||||
if ( ! empty( $users ) ) {
|
if ( ! empty( $users ) ) {
|
||||||
foreach ( $users as $user_id ) {
|
foreach ( $users as $user_id ) {
|
||||||
remove_user_from_blog( $user_id, $blog_id) ;
|
remove_user_from_blog( $user_id, $blog_id );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
update_blog_status( $blog_id, 'deleted', 1 );
|
update_blog_status( $blog_id, 'deleted', 1 );
|
||||||
|
|
||||||
|
// Don't destroy the initial, main, or root blog.
|
||||||
|
if ( $drop && ( 1 == $blog_id || is_main_site( $blog_id ) || ( $blog->path == $current_site->path && $blog->domain == $current_site->domain ) ) )
|
||||||
|
$drop = false;
|
||||||
|
|
||||||
if ( $drop ) {
|
if ( $drop ) {
|
||||||
if ( substr( $blog_prefix, -1 ) == '_' )
|
|
||||||
$blog_prefix = substr( $blog_prefix, 0, -1 ) . '\_';
|
|
||||||
|
|
||||||
$drop_tables = $wpdb->get_results( "SHOW TABLES LIKE '{$blog_prefix}%'", ARRAY_A );
|
$drop_tables = apply_filters( 'wpmu_drop_tables', $wpdb->tables( 'blog' ) );
|
||||||
$drop_tables = apply_filters( 'wpmu_drop_tables', $drop_tables );
|
|
||||||
|
|
||||||
reset( $drop_tables );
|
foreach ( (array) $drop_tables as $table ) {
|
||||||
foreach ( (array) $drop_tables as $drop_table) {
|
$wpdb->query( "DROP TABLE IF EXISTS `$table`" );
|
||||||
$wpdb->query( "DROP TABLE IF EXISTS ". current( $drop_table ) ."" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->blogs WHERE blog_id = %d", $blog_id ) );
|
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->blogs WHERE blog_id = %d", $blog_id ) );
|
||||||
$dir = apply_filters( 'wpmu_delete_blog_upload_dir', WP_CONTENT_DIR . "/blogs.dir/{$blog_id}/files/", $blog_id );
|
$dir = apply_filters( 'wpmu_delete_blog_upload_dir', WP_CONTENT_DIR . "/blogs.dir/{$blog_id}/files/", $blog_id );
|
||||||
$dir = rtrim( $dir, DIRECTORY_SEPARATOR );
|
$dir = rtrim( $dir, DIRECTORY_SEPARATOR );
|
||||||
@ -120,17 +122,7 @@ function wpmu_delete_blog( $blog_id, $drop = false ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key = '{$blog_prefix}autosave_draft_ids'" );
|
if ( $switch )
|
||||||
$blogs = get_site_option( 'blog_list' );
|
|
||||||
if ( is_array( $blogs ) ) {
|
|
||||||
foreach ( $blogs as $n => $blog ) {
|
|
||||||
if ( $blog['blog_id'] == $blog_id )
|
|
||||||
unset( $blogs[$n] );
|
|
||||||
}
|
|
||||||
update_site_option( 'blog_list', $blogs );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( $switch === true )
|
|
||||||
restore_current_blog();
|
restore_current_blog();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user