Ticket #32154: 32154.02.patch
| File 32154.02.patch, 5.5 KB (added by , 11 years ago) |
|---|
-
wp-admin/includes/upgrade.php
1208 1208 add_site_option( 'siteurl', '' ); 1209 1209 1210 1210 // 3.0 screen options key name changes. 1211 if ( is_main_site() && !defined('DO_NOT_UPGRADE_GLOBAL_TABLES') ) {1211 if ( wp_can_upgrade_global_tables() ) { 1212 1212 $sql = "DELETE FROM $wpdb->usermeta 1213 1213 WHERE meta_key LIKE %s 1214 1214 OR meta_key LIKE %s … … 1243 1243 function upgrade_330() { 1244 1244 global $wp_current_db_version, $wpdb, $wp_registered_widgets, $sidebars_widgets; 1245 1245 1246 if ( $wp_current_db_version < 19061 && is_main_site() && ! defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES') ) {1246 if ( $wp_current_db_version < 19061 && wp_can_upgrade_global_tables() ) { 1247 1247 $wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key IN ('show_admin_bar_admin', 'plugins_last_view')" ); 1248 1248 } 1249 1249 … … 1324 1324 $wpdb->show_errors(); 1325 1325 } 1326 1326 1327 if ( $wp_current_db_version < 20022 && is_main_site() && ! defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES') ) {1327 if ( $wp_current_db_version < 20022 && wp_can_upgrade_global_tables() ) { 1328 1328 $wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key = 'themes_last_view'" ); 1329 1329 } 1330 1330 … … 1348 1348 if ( $wp_current_db_version < 22006 && $wpdb->get_var( "SELECT link_id FROM $wpdb->links LIMIT 1" ) ) 1349 1349 update_option( 'link_manager_enabled', 1 ); // Previously set to 0 by populate_options() 1350 1350 1351 if ( $wp_current_db_version < 21811 && is_main_site() && ! defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES') ) {1351 if ( $wp_current_db_version < 21811 && wp_can_upgrade_global_tables() ) { 1352 1352 $meta_keys = array(); 1353 1353 foreach ( array_merge( get_post_types(), get_taxonomies() ) as $name ) { 1354 1354 if ( false !== strpos( $name, '-' ) ) … … 1564 1564 1565 1565 // 4.2 1566 1566 if ( $wp_current_db_version < 31351 && $wpdb->charset === 'utf8mb4' ) { 1567 if ( ! ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) && DO_NOT_UPGRADE_GLOBAL_TABLES) ) {1568 $wpdb->query( "ALTER TABLE $wpdb->usermetaDROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );1569 $wpdb->query( "ALTER TABLE $wpdb->siteDROP INDEX domain, ADD INDEX domain(domain(140),path(51))" );1570 $wpdb->query( "ALTER TABLE $wpdb->sitemetaDROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );1571 $wpdb->query( "ALTER TABLE $wpdb->signupsDROP INDEX domain, ADD INDEX domain(domain(140),path(51))" );1567 if ( wp_can_upgrade_global_tables() ) { 1568 $wpdb->query( "ALTER TABLE `{$wpdb->usermeta}` DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" ); 1569 $wpdb->query( "ALTER TABLE `{$wpdb->site}` DROP INDEX domain, ADD INDEX domain(domain(140),path(51))" ); 1570 $wpdb->query( "ALTER TABLE `{$wpdb->sitemeta}` DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" ); 1571 $wpdb->query( "ALTER TABLE `{$wpdb->signups}` DROP INDEX domain, ADD INDEX domain(domain(140),path(51))" ); 1572 1572 1573 1573 $tables = $wpdb->tables( 'global' ); 1574 1574 … … 1870 1870 1871 1871 $global_tables = $wpdb->tables( 'global' ); 1872 1872 foreach ( $cqueries as $table => $qry ) { 1873 // Upgrade global tables only for the main site. Don't upgrade at all if DO_NOT_UPGRADE_GLOBAL_TABLES is defined.1874 if ( in_array( $table, $global_tables ) && ( !is_main_site() || defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' )) ) {1873 // Upgrade global tables only for the main site. Don't upgrade at all if conditions are not optimal. 1874 if ( in_array( $table, $global_tables ) && ! wp_can_upgrade_global_tables() ) { 1875 1875 unset( $cqueries[ $table ], $for_update[ $table ] ); 1876 1876 continue; 1877 1877 } … … 2380 2380 } 2381 2381 2382 2382 // Multisite schema upgrades. 2383 if ( $wp_current_db_version < 25448 && is_multisite() && ! defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) && is_main_network() ) {2383 if ( $wp_current_db_version < 25448 && wp_can_upgrade_global_tables() ) { 2384 2384 2385 2385 // Upgrade verions prior to 3.7 2386 2386 if ( $wp_current_db_version < 25179 ) { … … 2403 2403 2404 2404 // Upgrade versions prior to 4.2. 2405 2405 if ( $wp_current_db_version < 31351 ) { 2406 if ( ! is_multisite() ) {2406 if ( upgrade_global_tables() ) { 2407 2407 $wpdb->query( "ALTER TABLE $wpdb->usermeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" ); 2408 2408 } 2409 2409 $wpdb->query( "ALTER TABLE $wpdb->terms DROP INDEX slug, ADD INDEX slug(slug(191))" ); … … 2438 2438 dbDelta( $ms_queries ); 2439 2439 } 2440 2440 endif; 2441 2442 /** 2443 * Can global tables be upgraded? 2444 * 2445 * This function performs a series of checks to ensure the environment allows 2446 * for the safe upgrading of global WordPress database tables. It is necessary 2447 * because global tables will commonly grow to millions of rows on large 2448 * installations, and the ability to control their upgrade routines can be 2449 * critical to the operation of large networks. 2450 * 2451 * In a future iteration, this function may use `wp_is_large_network()` to more- 2452 * intelligently prevent global table upgrades. Until then, we make sure 2453 * WordPress is on the main site of the main network, to avoid running queries 2454 * more than once in multi-site or multi-network environments. 2455 * 2456 * @since WordPress 4.3.0 2457 * 2458 * @return boolean 2459 */ 2460 function wp_can_upgrade_global_tables() { 2461 2462 // Assume global tables should be updated 2463 $retval = true; 2464 2465 // Return false early if explicitly not upgrading 2466 if ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) { 2467 return false; 2468 } 2469 2470 // Set to false if not on main network (does not matter if not multi-network) 2471 if ( ! is_main_network() ) { 2472 $retval = false; 2473 } 2474 2475 // Set to false if not on main site of current network (does not matter if not multi-site) 2476 if ( ! is_main_site() ) { 2477 $retval = false; 2478 } 2479 2480 return (bool) apply_filters( 'wp_can_upgrade_global_tables', $retval ); 2481 }