WordPress.org

Make WordPress Core

Ticket #30121: 30121.2.diff

File 30121.2.diff, 4.3 KB (added by jeremyfelt, 5 years ago)
  • src/wp-admin/includes/ms.php

     
    8585
    8686        $current_site = get_current_site();
    8787
     88        // If a full blog object is not available, do not destroy anything.
     89        if ( $drop && ! $blog ) {
     90                $drop = false;
     91        }
     92
    8893        // Don't destroy the initial, main, or root blog.
    89         if ( $drop && ( 1 == $blog_id || is_main_site( $blog_id ) || ( $blog->path == $current_site->path && $blog->domain == $current_site->domain ) ) )
     94        if ( $drop && ( 1 == $blog_id || is_main_site( $blog_id ) || ( $blog->path == $current_site->path && $blog->domain == $current_site->domain ) ) ) {
     95                $drop = false;
     96        }
     97
     98        // If ms_files_rewriting is enabled and upload_path is empty, wp_upload_dir is not reliable.
     99        if ( $drop && get_site_option( 'ms_files_rewriting' ) && empty( get_option( 'upload_path' ) ) ) {
    90100                $drop = false;
     101        }
    91102
    92103        if ( $drop ) {
     104                $uploads = wp_upload_dir();
     105
    93106                $tables = $wpdb->tables( 'blog' );
    94107                /**
    95108                 * Filter the tables to drop when the blog is deleted.
     
    107120
    108121                $wpdb->delete( $wpdb->blogs, array( 'blog_id' => $blog_id ) );
    109122
    110                 $uploads = wp_upload_dir();
    111123                /**
    112124                 * Filter the upload base directory to delete when the blog is deleted.
    113125                 *
  • tests/phpunit/tests/multisite/ms-files-rewriting.php

     
    5555                $this->assertEquals( '', $info2['error'] );
    5656                restore_current_blog();
    5757        }
     58
     59        /**
     60         * When a site is deleted with wpmu_delete_blog(), only the files associated with
     61         * that site should be removed. When wpmu_delete_blog() is run a second time, nothing
     62         * should change with upload directories.
     63         */
     64        function test_upload_directories_after_multiple_wpmu_delete_blog_with_ms_files() {
     65                $filename = rand_str().'.jpg';
     66                $contents = rand_str();
     67
     68                // Upload a file to the main site on the network.
     69                $file1 = wp_upload_bits( $filename, null, $contents );
     70
     71                $blog_id = $this->factory->blog->create();
     72
     73                switch_to_blog( $blog_id );
     74                $file2 = wp_upload_bits( $filename, null, $contents );
     75                restore_current_blog();
     76
     77                wpmu_delete_blog( $blog_id, true );
     78
     79                // The file on the main site should still exist. The file on the deleted site should not.
     80                $this->assertTrue( file_exists( $file1['file'] ) );
     81                $this->assertFalse( file_exists( $file2['file'] ) );
     82
     83                wpmu_delete_blog( $blog_id, true );
     84
     85                // The file on the main site should still exist. The file on the deleted site should not.
     86                $this->assertTrue( file_exists( $file1['file'] ) );
     87                $this->assertFalse( file_exists( $file2['file'] ) );
     88        }
    5889}
    5990
    6091endif;
     92 No newline at end of file
  • tests/phpunit/tests/multisite/site.php

     
    274274                $this->assertEquals( 1, get_blog_count() );
    275275        }
    276276
     277        /**
     278         * When a site is deleted with wpmu_delete_blog(), only the files associated with
     279         * that site should be removed. When wpmu_delete_blog() is run a second time, nothing
     280         * should change with upload directories.
     281         */
     282        function test_upload_directories_after_multiple_wpmu_delete_blog() {
     283                $filename = rand_str().'.jpg';
     284                $contents = rand_str();
     285
     286                // Upload a file to the main site on the network.
     287                $file1 = wp_upload_bits( $filename, null, $contents );
     288
     289                $blog_id = $this->factory->blog->create();
     290
     291                switch_to_blog( $blog_id );
     292                $file2 = wp_upload_bits( $filename, null, $contents );
     293                restore_current_blog();
     294
     295                wpmu_delete_blog( $blog_id, true );
     296
     297                // The file on the main site should still exist. The file on the deleted site should not.
     298                $this->assertTrue( file_exists( $file1['file'] ) );
     299                $this->assertFalse( file_exists( $file2['file'] ) );
     300
     301                wpmu_delete_blog( $blog_id, true );
     302
     303                // The file on the main site should still exist. The file on the deleted site should not.
     304                $this->assertTrue( file_exists( $file1['file'] ) );
     305                $this->assertFalse( file_exists( $file2['file'] ) );
     306        }
     307
    277308        function test_wpmu_update_blogs_date() {
    278309                global $wpdb;
    279310