Ticket #42251: 42251.2.diff
File 42251.2.diff, 5.1 KB (added by , 5 years ago) |
---|
-
src/wp-admin/includes/schema.php
1167 1167 } 1168 1168 } 1169 1169 1170 if ( function_exists( 'clean_network_cache' ) ) { 1171 clean_network_cache( $network_id ); 1172 } else { 1173 wp_cache_delete( $network_id, 'networks' ); 1174 } 1175 1170 1176 wp_cache_delete( 'networks_have_paths', 'site-options' ); 1171 1177 1172 1178 if ( ! is_multisite() ) { -
src/wp-includes/class-wp-network.php
101 101 102 102 $_network = wp_cache_get( $network_id, 'networks' ); 103 103 104 if ( !$_network ) {104 if ( false === $_network ) { 105 105 $_network = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->site} WHERE id = %d LIMIT 1", $network_id ) ); 106 106 107 107 if ( empty( $_network ) || is_wp_error( $_network ) ) { 108 return false;108 $_network = -1; 109 109 } 110 110 111 111 wp_cache_add( $network_id, $_network, 'networks' ); 112 112 } 113 113 114 if ( is_numeric( $_network ) ) { 115 return false; 116 } 117 114 118 return new WP_Network( $_network ); 115 119 } 116 120 -
src/wp-includes/class-wp-site.php
162 162 163 163 $_site = wp_cache_get( $site_id, 'sites' ); 164 164 165 if ( !$_site ) {165 if ( false === $_site ) { 166 166 $_site = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->blogs} WHERE blog_id = %d LIMIT 1", $site_id ) ); 167 167 168 168 if ( empty( $_site ) || is_wp_error( $_site ) ) { 169 return false;169 $_site = -1; 170 170 } 171 171 172 172 wp_cache_add( $site_id, $_site, 'sites' ); 173 173 } 174 174 175 if ( is_numeric( $_site ) ) { 176 return false; 177 } 178 175 179 return new WP_Site( $_site ); 176 180 } 177 181 -
tests/phpunit/tests/multisite/network.php
613 613 614 614 $this->assertSame( (string) self::$different_site_ids[0], $network->blog_id ); 615 615 } 616 617 /** 618 * @ticket 42251 619 */ 620 public function test_wp_site_get_instance_doesnt_exist() { 621 $this->assertFalse( WP_Network::get_instance( $this->_get_next_network_id() ) ); 622 } 623 624 /** 625 * @ticket 42251 626 */ 627 public function test_wp_site_get_instance_doesnt_exist_but_later_exists() { 628 $new_site_id = $this->_get_next_network_id(); 629 $this->assertFalse( WP_Network::get_instance( $new_site_id ) ); 630 $new_network = $this->factory()->network->create_and_get(); 631 //make sure we were right about what the new network's ID would be 632 $this->assertEquals( $new_site_id, $new_network->id ); 633 //verify that if we fetch the network now, it's no longer false 634 $fetched_network = WP_Network::get_instance( $new_site_id ); 635 $this->assertInstanceOf( 'WP_Network', $fetched_network ); 636 $this->assertEquals( $new_site_id, $fetched_network->id ); 637 } 638 639 /** 640 * Gets the ID of the site with the highest ID 641 * @return int 642 */ 643 protected function _get_next_network_id() { 644 global $wpdb; 645 //create an extra network, just to make sure we know the ID of the following one 646 static::factory()->network->create(); 647 return (int) $wpdb->get_var( 'SELECT id FROM ' . $wpdb->site . ' ORDER BY id DESC LIMIT 1' ) + 1; 648 } 616 649 } 617 650 618 651 endif; -
tests/phpunit/tests/multisite/site.php
2370 2370 } 2371 2371 2372 2372 /** 2373 * @ticket 42251 2374 */ 2375 public function test_wp_site_get_instance_doesnt_exist() { 2376 $this->assertFalse( WP_Site::get_instance( $this->_get_next_site_id() ) ); 2377 } 2378 2379 /** 2380 * @ticket 42251 2381 */ 2382 public function test_wp_site_get_instance_doesnt_exist_but_later_exists() { 2383 $new_site_id = $this->_get_next_site_id(); 2384 $this->assertFalse( WP_Site::get_instance( $new_site_id ) ); 2385 $new_site = $this->factory()->blog->create_and_get(); 2386 //double check we got the ID of the new site correct 2387 $this->assertEquals( $new_site_id, $new_site->blog_id ); 2388 //verify that if we fetch the site now, it's no longer false 2389 $fetched_site = WP_Site::get_instance( $new_site_id ); 2390 $this->assertInstanceOf( 'WP_Site', $fetched_site ); 2391 $this->assertEquals( $new_site_id, $fetched_site->blog_id ); 2392 2393 } 2394 2395 /** 2396 * Gets the ID of the next site that will get inserted 2397 * @return int 2398 */ 2399 protected function _get_next_site_id() { 2400 global $wpdb; 2401 //create an entry 2402 static::factory()->blog->create(); 2403 //get the ID after it 2404 return (int)$wpdb->get_var( 'SELECT blog_id FROM ' . $wpdb->blogs . ' ORDER BY blog_ID DESC LIMIT 1' ) + 1; 2405 } 2406 2407 /** 2373 2408 * Capture the $meta value passed to the wpmu_new_blog action and compare it. 2374 2409 */ 2375 2410 public function wpmu_new_blog_callback( $blog_id, $user_id, $domain, $path, $network_id, $meta ) {