Changeset 45910
- Timestamp:
- 08/29/2019 12:41:45 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/schema.php
r45805 r45910 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 -
trunk/src/wp-includes/class-wp-network.php
r42876 r45910 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 } 113 114 if ( is_numeric( $_network ) ) { 115 return false; 112 116 } 113 117 … … 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; … … 458 462 } 459 463 } 460 if ( $network->path === '/') {464 if ( '/' === $network->path ) { 461 465 $found = true; 462 466 break; -
trunk/src/wp-includes/class-wp-site.php
r45232 r45910 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 } 174 175 if ( is_numeric( $_site ) ) { 176 return false; 173 177 } 174 178 -
trunk/src/wp-includes/ms-site.php
r45236 r45910 70 70 } 71 71 72 clean_blog_cache( $wpdb->insert_id ); 73 72 74 $new_site = get_site( $wpdb->insert_id ); 73 75 … … 75 77 return new WP_Error( 'get_site_error', __( 'Could not retrieve site data.' ) ); 76 78 } 77 78 clean_blog_cache( $new_site );79 79 80 80 /** -
trunk/tests/phpunit/tests/multisite/network.php
r42343 r45910 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 -
trunk/tests/phpunit/tests/multisite/site.php
r45607 r45910 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 */
Note: See TracChangeset
for help on using the changeset viewer.