Changeset 33057
- Timestamp:
- 07/03/2015 04:33:14 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/upgrade.php
r33055 r33057 1253 1253 1254 1254 // 3.0 screen options key name changes. 1255 if ( is_main_site() && !defined('DO_NOT_UPGRADE_GLOBAL_TABLES') ) {1255 if ( wp_should_upgrade_global_tables() ) { 1256 1256 $sql = "DELETE FROM $wpdb->usermeta 1257 1257 WHERE meta_key LIKE %s … … 1293 1293 global $wp_current_db_version, $wpdb, $wp_registered_widgets, $sidebars_widgets; 1294 1294 1295 if ( $wp_current_db_version < 19061 && is_main_site() && ! defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES') ) {1295 if ( $wp_current_db_version < 19061 && wp_should_upgrade_global_tables() ) { 1296 1296 $wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key IN ('show_admin_bar_admin', 'plugins_last_view')" ); 1297 1297 } … … 1377 1377 } 1378 1378 1379 if ( $wp_current_db_version < 20022 && is_main_site() && ! defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES') ) {1379 if ( $wp_current_db_version < 20022 && wp_should_upgrade_global_tables() ) { 1380 1380 $wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key = 'themes_last_view'" ); 1381 1381 } … … 1404 1404 update_option( 'link_manager_enabled', 1 ); // Previously set to 0 by populate_options() 1405 1405 1406 if ( $wp_current_db_version < 21811 && is_main_site() && ! defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES') ) {1406 if ( $wp_current_db_version < 21811 && wp_should_upgrade_global_tables() ) { 1407 1407 $meta_keys = array(); 1408 1408 foreach ( array_merge( get_post_types(), get_taxonomies() ) as $name ) { … … 1674 1674 // 4.2 1675 1675 if ( $wp_current_db_version < 31351 && $wpdb->charset === 'utf8mb4' ) { 1676 if ( ! ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) && DO_NOT_UPGRADE_GLOBAL_TABLES) ) {1676 if ( wp_should_upgrade_global_tables() ) { 1677 1677 $wpdb->query( "ALTER TABLE $wpdb->usermeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" ); 1678 1678 $wpdb->query( "ALTER TABLE $wpdb->site DROP INDEX domain, ADD INDEX domain(domain(140),path(51))" ); … … 1690 1690 // 4.3 1691 1691 if ( $wp_current_db_version < 33055 && 'utf8mb4' === $wpdb->charset ) { 1692 if ( ! ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) && DO_NOT_UPGRADE_GLOBAL_TABLES) ) {1692 if ( wp_should_upgrade_global_tables() ) { 1693 1693 $upgrade = false; 1694 1694 $indexes = $wpdb->get_results( "SHOW INDEXES FROM $wpdb->signups" ); … … 2099 2099 $global_tables = $wpdb->tables( 'global' ); 2100 2100 foreach ( $cqueries as $table => $qry ) { 2101 // Upgrade global tables only for the main site. Don't upgrade at all if DO_NOT_UPGRADE_GLOBAL_TABLES is defined.2102 if ( in_array( $table, $global_tables ) && ( !is_main_site() || defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' )) ) {2101 // Upgrade global tables only for the main site. Don't upgrade at all if conditions are not optimal. 2102 if ( in_array( $table, $global_tables ) && ! wp_should_upgrade_global_tables() ) { 2103 2103 unset( $cqueries[ $table ], $for_update[ $table ] ); 2104 2104 continue; … … 2617 2617 2618 2618 // Multisite schema upgrades. 2619 if ( $wp_current_db_version < 25448 && is_multisite() && ! defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) && is_main_network() ) {2619 if ( $wp_current_db_version < 25448 && is_multisite() && wp_should_upgrade_global_tables() ) { 2620 2620 2621 2621 // Upgrade verions prior to 3.7 … … 2635 2635 // Upgrade versions prior to 4.2. 2636 2636 if ( $wp_current_db_version < 31351 ) { 2637 if ( ! is_multisite() ) {2637 if ( wp_should_upgrade_global_tables() ) { 2638 2638 $wpdb->query( "ALTER TABLE $wpdb->usermeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" ); 2639 2639 } … … 2672 2672 } 2673 2673 endif; 2674 2675 /** 2676 * Determine if global tables should be upgraded. 2677 * 2678 * This function performs a series of checks to ensure the environment allows 2679 * for the safe upgrading of global WordPress database tables. It is necessary 2680 * because global tables will commonly grow to millions of rows on large 2681 * installations, and the ability to control their upgrade routines can be 2682 * critical to the operation of large networks. 2683 * 2684 * In a future iteration, this function may use `wp_is_large_network()` to more- 2685 * intelligently prevent global table upgrades. Until then, we make sure 2686 * WordPress is on the main site of the main network, to avoid running queries 2687 * more than once in multi-site or multi-network environments. 2688 * 2689 * @since 4.3.0 2690 * 2691 * @return bool Whether to run the upgrade routines on global tables. 2692 */ 2693 function wp_should_upgrade_global_tables() { 2694 2695 // Return false early if explicitly not upgrading 2696 if ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) { 2697 return false; 2698 } 2699 2700 // Assume global tables should be upgraded 2701 $should_upgrade = true; 2702 2703 // Set to false if not on main network (does not matter if not multi-network) 2704 if ( ! is_main_network() ) { 2705 $should_upgrade = false; 2706 } 2707 2708 // Set to false if not on main site of current network (does not matter if not multi-site) 2709 if ( ! is_main_site() ) { 2710 $should_upgrade = false; 2711 } 2712 2713 /** 2714 * Filter if upgrade routines should be run on global tables in multisite. 2715 * 2716 * @param bool $should_upgrade Whether to run the upgrade routines on global tables. 2717 */ 2718 return apply_filters( 'wp_should_upgrade_global_tables', $should_upgrade ); 2719 }
Note: See TracChangeset
for help on using the changeset viewer.