Ticket #42251: 42251.3.diff
File 42251.3.diff, 6.8 KB (added by , 4 years ago) |
---|
-
src/wp-admin/includes/schema.php
1159 1159 } 1160 1160 } 1161 1161 1162 if ( function_exists( 'clean_network_cache' ) ) { 1163 clean_network_cache( $network_id ); 1164 } else { 1165 wp_cache_delete( $network_id, 'networks' ); 1166 } 1167 1162 1168 wp_cache_delete( 'networks_have_paths', 'site-options' ); 1163 1169 1164 1170 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 … … 231 235 return (int) $this->blog_id; 232 236 } 233 237 234 if ( ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) && $this->domain === DOMAIN_CURRENT_SITE && $this->path === PATH_CURRENT_SITE)235 || ( defined( 'SITE_ID_CURRENT_SITE' ) && $this->id == SITE_ID_CURRENT_SITE) ) {238 if ( ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) && DOMAIN_CURRENT_SITE === $this->domain && PATH_CURRENT_SITE === $this->path ) 239 || ( defined( 'SITE_ID_CURRENT_SITE' ) && SITE_ID_CURRENT_SITE == $this->id ) ) { 236 240 if ( defined( 'BLOG_ID_CURRENT_SITE' ) ) { 237 241 $this->blog_id = (string) BLOG_ID_CURRENT_SITE; 238 242 … … 457 461 break; 458 462 } 459 463 } 460 if ( $network->path === '/') {464 if ( '/' === $network->path ) { 461 465 $found = true; 462 466 break; 463 467 } -
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 -
src/wp-includes/ms-site.php
69 69 return new WP_Error( 'db_insert_error', __( 'Could not insert site into the database.' ), $wpdb->last_error ); 70 70 } 71 71 72 clean_blog_cache( $wpdb->insert_id ); 73 72 74 $new_site = get_site( $wpdb->insert_id ); 73 75 74 76 if ( ! $new_site ) { 75 77 return new WP_Error( 'get_site_error', __( 'Could not retrieve site data.' ) ); 76 78 } 77 79 78 clean_blog_cache( $new_site );79 80 80 /** 81 81 * Fires once a site has been inserted into the database. 82 82 * -
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_get_network_not_found_cache() { 621 global $wpdb; 622 623 $new_network_id = $this->_get_next_network_id(); 624 $this->assertNull( get_network( $new_network_id ) ); 625 626 $num_queries = $wpdb->num_queries; 627 $this->assertNull( get_network( $new_network_id ) ); 628 $this->assertSame( $num_queries, $wpdb->num_queries ); 629 } 630 631 /** 632 * @ticket 42251 633 */ 634 public function test_get_network_not_found_cache_clear() { 635 $new_network_id = $this->_get_next_network_id(); 636 $this->assertNull( get_network( $new_network_id ) ); 637 638 $new_network = $this->factory()->network->create_and_get(); 639 640 // Double-check we got the ID of the new network correct. 641 $this->assertEquals( $new_network_id, $new_network->id ); 642 643 // Verify that if we fetch the network now, it's no longer false. 644 $fetched_network = get_network( $new_network_id ); 645 $this->assertInstanceOf( 'WP_Network', $fetched_network ); 646 $this->assertEquals( $new_network_id, $fetched_network->id ); 647 } 648 649 /** 650 * Gets the ID of the site with the highest ID 651 * @return int 652 */ 653 protected function _get_next_network_id() { 654 global $wpdb; 655 //create an extra network, just to make sure we know the ID of the following one 656 static::factory()->network->create(); 657 return (int) $wpdb->get_var( 'SELECT id FROM ' . $wpdb->site . ' ORDER BY id DESC LIMIT 1' ) + 1; 658 } 616 659 } 617 660 618 661 endif; -
tests/phpunit/tests/multisite/site.php
2384 2384 } 2385 2385 2386 2386 /** 2387 * @ticket 42251 2388 */ 2389 public function test_get_site_not_found_cache() { 2390 global $wpdb; 2391 2392 $new_site_id = $this->_get_next_site_id(); 2393 $this->assertNull( get_site( $new_site_id ) ); 2394 2395 $num_queries = $wpdb->num_queries; 2396 $this->assertNull( get_site( $new_site_id ) ); 2397 $this->assertSame( $num_queries, $wpdb->num_queries ); 2398 } 2399 2400 /** 2401 * @ticket 42251 2402 */ 2403 public function test_get_site_not_found_cache_clear() { 2404 $new_site_id = $this->_get_next_site_id(); 2405 $this->assertNull( get_site( $new_site_id ) ); 2406 2407 $new_site = $this->factory()->blog->create_and_get(); 2408 2409 // Double-check we got the ID of the new site correct. 2410 $this->assertEquals( $new_site_id, $new_site->blog_id ); 2411 2412 // Verify that if we fetch the site now, it's no longer false. 2413 $fetched_site = get_site( $new_site_id ); 2414 $this->assertInstanceOf( 'WP_Site', $fetched_site ); 2415 $this->assertEquals( $new_site_id, $fetched_site->blog_id ); 2416 2417 } 2418 2419 /** 2420 * Gets the ID of the next site that will get inserted 2421 * @return int 2422 */ 2423 protected function _get_next_site_id() { 2424 global $wpdb; 2425 //create an entry 2426 static::factory()->blog->create(); 2427 //get the ID after it 2428 return (int) $wpdb->get_var( 'SELECT blog_id FROM ' . $wpdb->blogs . ' ORDER BY blog_ID DESC LIMIT 1' ) + 1; 2429 } 2430 2431 /** 2387 2432 * Capture the $meta value passed to the wpmu_new_blog action and compare it. 2388 2433 */ 2389 2434 public function wpmu_new_blog_callback( $blog_id, $user_id, $domain, $path, $network_id, $meta ) {