Changeset 31349 for trunk/src/wp-admin/includes/upgrade.php
- Timestamp:
- 02/06/2015 04:50:19 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/upgrade.php
r31246 r31349 519 519 if ( $wp_current_db_version < 29630 ) 520 520 upgrade_400(); 521 522 if ( $wp_current_db_version < 31349 ) 523 upgrade_420(); 521 524 522 525 maybe_disable_link_manager(); … … 1408 1411 1409 1412 /** 1413 * Execute changes made in WordPress 4.2.0. 1414 * 1415 * @since 4.2.0 1416 */ 1417 function upgrade_420() { 1418 global $wp_current_db_version, $wpdb; 1419 1420 if ( $wp_current_db_version < 31349 && $wpdb->charset === 'utf8mb4' ) { 1421 if ( is_multisite() ) { 1422 $tables = $wpdb->tables( 'blog' ); 1423 } else { 1424 $tables = $wpdb->tables( 'all' ); 1425 } 1426 1427 foreach ( $tables as $table ) { 1428 maybe_convert_table_to_utf8mb4( $table ); 1429 } 1430 } 1431 } 1432 1433 /** 1410 1434 * Executes network-level upgrade routines. 1411 1435 * … … 1503 1527 } 1504 1528 } 1529 1530 // 4.2 1531 if ( $wp_current_db_version < 31349 && $wpdb->charset === 'utf8mb4' ) { 1532 if ( ! ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) && DO_NOT_UPGRADE_GLOBAL_TABLES ) ) { 1533 $wpdb->query( "ALTER TABLE $wpdb->site DROP INDEX domain, ADD INDEX domain(domain(140),path(51))" ); 1534 $wpdb->query( "ALTER TABLE $wpdb->sitemeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" ); 1535 $wpdb->query( "ALTER TABLE $wpdb->signups DROP INDEX domain, ADD INDEX domain(domain(140),path(51))" ); 1536 1537 $tables = $wpdb->tables( 'global' ); 1538 1539 foreach ( $tables as $table ) { 1540 maybe_convert_table_to_utf8mb4( $table ); 1541 } 1542 } 1543 } 1505 1544 } 1506 1545 … … 1606 1645 } 1607 1646 return false; 1647 } 1648 1649 /** 1650 * If a table only contains utf8 or utf8mb4 columns, convert it to utf8mb4. 1651 * 1652 * @since 4.2.0 1653 * 1654 * @param string $table The table to convert. 1655 * @return bool true if the table was converted, false if it wasn't. 1656 */ 1657 function maybe_convert_table_to_utf8mb4( $table ) { 1658 global $wpdb; 1659 1660 $results = $wpdb->get_results( "SHOW FULL COLUMNS FROM `$table`" ); 1661 if ( ! $results ) { 1662 return false; 1663 } 1664 1665 $has_utf8 = false; 1666 foreach ( $results as $column ) { 1667 if ( $column->Collation ) { 1668 if ( 'utf8' === $column->Collation ) { 1669 $has_utf8 = true; 1670 } elseif ( 'utf8mb4' !== $column->Collation ) { 1671 // Don't upgrade tables that have non-utf8 columns. 1672 return false; 1673 } 1674 } 1675 } 1676 1677 if ( ! $has_utf8 ) { 1678 // Don't bother upgrading tables that don't have utf8 columns. 1679 return false; 1680 } 1681 1682 return $wpdb->query( "ALTER TABLE $table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci" ); 1608 1683 } 1609 1684 … … 2285 2360 $wpdb->query( "ALTER TABLE $wpdb->terms DROP INDEX slug" ); 2286 2361 } 2362 2363 // Upgrade versions prior to 4.2. 2364 if ( $wp_current_db_version < 31349 ) { 2365 // So that we can change tables to utf8mb4, we need to shorten the index lengths to less than 767 bytes 2366 $wpdb->query( "ALTER TABLE $wpdb->usermeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" ); 2367 $wpdb->query( "ALTER TABLE $wpdb->terms DROP INDEX slug, ADD INDEX slug(slug(191))" ); 2368 $wpdb->query( "ALTER TABLE $wpdb->terms DROP INDEX name, ADD INDEX name(name(191))" ); 2369 $wpdb->query( "ALTER TABLE $wpdb->commentmeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" ); 2370 $wpdb->query( "ALTER TABLE $wpdb->postmeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" ); 2371 $wpdb->query( "ALTER TABLE $wpdb->posts DROP INDEX post_name, ADD INDEX post_name(post_name(191))" ); 2372 } 2287 2373 } 2288 2374
Note: See TracChangeset
for help on using the changeset viewer.