Changeset 47122 for trunk/src/wp-admin/includes/upgrade.php
- Timestamp:
- 01/29/2020 12:43:23 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/upgrade.php
r47060 r47122 155 155 global $wpdb, $wp_rewrite, $table_prefix; 156 156 157 // Default category 157 // Default category. 158 158 $cat_name = __( 'Uncategorized' ); 159 159 /* translators: Default category slug. */ … … 200 200 $cat_tt_id = $wpdb->insert_id; 201 201 202 // First post 202 // First post. 203 203 $now = current_time( 'mysql' ); 204 204 $now_gmt = current_time( 'mysql', 1 ); … … 220 220 ); 221 221 222 // Back-compat for pre-4.4 222 // Back-compat for pre-4.4. 223 223 $first_post = str_replace( 'SITE_URL', esc_url( network_home_url() ), $first_post ); 224 224 $first_post = str_replace( 'SITE_NAME', get_network()->site_name, $first_post ); … … 258 258 ); 259 259 260 // Default comment 260 // Default comment. 261 261 if ( is_multisite() ) { 262 262 $first_comment_author = get_site_option( 'first_comment_author' ); … … 287 287 ); 288 288 289 // First Page289 // First page. 290 290 if ( is_multisite() ) { 291 291 $first_page = get_site_option( 'first_page' ); … … 353 353 ); 354 354 355 // Privacy Policy page 355 // Privacy Policy page. 356 356 if ( is_multisite() ) { 357 357 // Disable by default unless the suggested content is provided. … … 494 494 $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix . 'capabilities' ) ); 495 495 496 // Delete any caps that snuck into the previously active blog. (Hardcoded to blog 1 for now.) TODO: Get previous_blog_id. 496 // Delete any caps that snuck into the previously active blog. (Hardcoded to blog 1 for now.) 497 // TODO: Get previous_blog_id. 497 498 if ( ! is_super_admin( $user_id ) && $user_id != 1 ) { 498 499 $wpdb->delete( … … 551 552 $test_url = ''; 552 553 553 // Test against a real WordPress Post554 // Test against a real WordPress post. 554 555 $first_post = get_page_by_path( sanitize_title( _x( 'hello-world', 'Default post slug' ) ), OBJECT, 'post' ); 555 556 if ( $first_post ) { … … 853 854 global $wpdb; 854 855 855 // Get the title and ID of every post, post_name to check if it already has a value 856 // Get the title and ID of every post, post_name to check if it already has a value. 856 857 $posts = $wpdb->get_results( "SELECT ID, post_title, post_name FROM $wpdb->posts WHERE post_name = ''" ); 857 858 if ( $posts ) { … … 892 893 if ( $allposts ) : 893 894 foreach ( $allposts as $post ) { 894 // Check to see if it's already been imported 895 // Check to see if it's already been imported. 895 896 $cat = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->post2cat WHERE post_id = %d AND category_id = %d", $post->ID, $post->post_category ) ); 896 if ( ! $cat && 0 != $post->post_category ) { // If there's no result 897 if ( ! $cat && 0 != $post->post_category ) { // If there's no result. 897 898 $wpdb->insert( 898 899 $wpdb->post2cat, … … 918 919 global $wpdb; 919 920 920 // Clean up indices, add a few 921 // Clean up indices, add a few. 921 922 add_clean_index( $wpdb->posts, 'post_name' ); 922 923 add_clean_index( $wpdb->posts, 'post_status' ); … … 955 956 } 956 957 957 // Get the GMT offset, we'll use that later on 958 // Get the GMT offset, we'll use that later on. 958 959 $all_options = get_alloptions_110(); 959 960 … … 969 970 $gmt_offset = -$diff_gmt_weblogger; 970 971 971 // Add a gmt_offset option, with value $gmt_offset 972 // Add a gmt_offset option, with value $gmt_offset. 972 973 add_option( 'gmt_offset', $gmt_offset ); 973 974 974 // Check if we already set the GMT fields (if we did, then 975 // MAX(post_date_gmt) can't be '0000-00-00 00:00:00' 976 // <michel_v> I just slapped myself silly for not thinking about it earlier 975 /* 976 * Check if we already set the GMT fields. If we did, then 977 * MAX(post_date_gmt) can't be '0000-00-00 00:00:00'. 978 * <michel_v> I just slapped myself silly for not thinking about it earlier. 979 */ 977 980 $got_gmt_fields = ! ( $wpdb->get_var( "SELECT MAX(post_date_gmt) FROM $wpdb->posts" ) == '0000-00-00 00:00:00' ); 978 981 979 982 if ( ! $got_gmt_fields ) { 980 983 981 // Add or subtract time to all dates, to get GMT dates 984 // Add or subtract time to all dates, to get GMT dates. 982 985 $add_hours = intval( $diff_gmt_weblogger ); 983 986 $add_minutes = intval( 60 * ( $diff_gmt_weblogger - $add_hours ) ); … … 1053 1056 } 1054 1057 1055 // Obsolete tables 1058 // Obsolete tables. 1056 1059 $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optionvalues' ); 1057 1060 $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiontypes' ); … … 1059 1062 $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiongroup_options' ); 1060 1063 1061 // Update comments table to use comment_type 1064 // Update comments table to use comment_type. 1062 1065 $wpdb->query( "UPDATE $wpdb->comments SET comment_type='trackback', comment_content = REPLACE(comment_content, '<trackback />', '') WHERE comment_content LIKE '<trackback />%'" ); 1063 1066 $wpdb->query( "UPDATE $wpdb->comments SET comment_type='pingback', comment_content = REPLACE(comment_content, '<pingback />', '') WHERE comment_content LIKE '<pingback />%'" ); 1064 1067 1065 // Some versions have multiple duplicate option_name rows with the same values 1068 // Some versions have multiple duplicate option_name rows with the same values. 1066 1069 $options = $wpdb->get_results( "SELECT option_name, COUNT(option_name) AS dupes FROM `$wpdb->options` GROUP BY option_name" ); 1067 1070 foreach ( $options as $option ) { … … 1371 1374 /* 1372 1375 * Create link_category terms for link categories. Create a map of link 1373 * cat IDs to link_category terms.1376 * category IDs to link_category terms. 1374 1377 */ 1375 1378 $link_cat_id_map = array(); … … 1412 1415 } 1413 1416 1414 // Associate links to cat s.1417 // Associate links to categories. 1415 1418 $links = $wpdb->get_results( "SELECT link_id, link_category FROM $wpdb->links" ); 1416 1419 if ( ! empty( $links ) ) { … … 1461 1464 1462 1465 if ( $wp_current_db_version < 4772 ) { 1463 // Obsolete linkcategories table 1466 // Obsolete linkcategories table. 1464 1467 $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'linkcategories' ); 1465 1468 } 1466 1469 1467 // Recalculate all counts 1470 // Recalculate all counts. 1468 1471 $terms = $wpdb->get_results( "SELECT term_taxonomy_id, taxonomy FROM $wpdb->term_taxonomy" ); 1469 1472 foreach ( (array) $terms as $term ) { … … 1587 1590 } 1588 1591 1589 // Update post_date for unpublished posts with empty timestamp 1592 // Update post_date for unpublished posts with empty timestamp. 1590 1593 if ( $wp_current_db_version < 8921 ) { 1591 1594 $wpdb->query( "UPDATE $wpdb->posts SET post_date = post_modified WHERE post_date = '0000-00-00 00:00:00'" ); … … 1638 1641 1639 1642 if ( $wp_current_db_version < 11958 ) { 1640 // Previously, setting depth to 1 would redundantly disable threading, but now 2 is the minimum depth to avoid confusion 1643 // Previously, setting depth to 1 would redundantly disable threading, 1644 // but now 2 is the minimum depth to avoid confusion. 1641 1645 if ( get_option( 'thread_comments_depth' ) == '1' ) { 1642 1646 update_option( 'thread_comments_depth', 2 ); … … 1770 1774 unset( $_sidebars_widgets ); 1771 1775 1772 // intentional fall-through to upgrade to the next version.1776 // Intentional fall-through to upgrade to the next version. 1773 1777 case 2: 1774 1778 $sidebars_widgets = retrieve_widgets(); … … 1828 1832 1829 1833 if ( $wp_current_db_version < 22006 && $wpdb->get_var( "SELECT link_id FROM $wpdb->links LIMIT 1" ) ) { 1830 update_option( 'link_manager_enabled', 1 ); // Previously set to 0 by populate_options() 1834 update_option( 'link_manager_enabled', 1 ); // Previously set to 0 by populate_options(). 1831 1835 } 1832 1836 … … 2022 2026 */ 2023 2027 function upgrade_431() { 2024 // Fix incorrect cron entries for term splitting 2028 // Fix incorrect cron entries for term splitting. 2025 2029 $cron_array = _get_cron_array(); 2026 2030 if ( isset( $cron_array['wp_batch_split_terms'] ) ) { … … 2139 2143 */ 2140 2144 function upgrade_530() { 2141 // The `admin_email_lifespan` option may have been set by an admin that just logged in, 2142 // saw the verification screen, clicked on a button there, and is now upgrading the db, 2143 // or by populate_options() that is called earlier in upgrade_all(). 2144 // In the second case `admin_email_lifespan` should be reset so the verification screen 2145 // is shown next time an admin logs in. 2145 /* 2146 * The `admin_email_lifespan` option may have been set by an admin that just logged in, 2147 * saw the verification screen, clicked on a button there, and is now upgrading the db, 2148 * or by populate_options() that is called earlier in upgrade_all(). 2149 * In the second case `admin_email_lifespan` should be reset so the verification screen 2150 * is shown next time an admin logs in. 2151 */ 2146 2152 if ( function_exists( 'current_user_can' ) && ! current_user_can( 'manage_options' ) ) { 2147 2153 update_option( 'admin_email_lifespan', 0 ); … … 2160 2166 global $wp_current_db_version, $wpdb; 2161 2167 2162 // Always clear expired transients 2168 // Always clear expired transients. 2163 2169 delete_expired_transients( true ); 2164 2170 2165 // 2.8 .2171 // 2.8 2166 2172 if ( $wp_current_db_version < 11549 ) { 2167 2173 $wpmu_sitewide_plugins = get_site_option( 'wpmu_sitewide_plugins' ); … … 2302 2308 2303 2309 // 2304 // General functions we use to actually do stuff 2310 // General functions we use to actually do stuff. 2305 2311 // 2306 2312 … … 2329 2335 } 2330 2336 2331 // Didn't find it try to create it..2337 // Didn't find it, so try to create it. 2332 2338 $wpdb->query( $create_ddl ); 2333 2339 … … 2354 2360 $wpdb->hide_errors(); 2355 2361 $wpdb->query( "ALTER TABLE `$table` DROP INDEX `$index`" ); 2356 // Now we need to take out all the extra ones we may have created 2362 // Now we need to take out all the extra ones we may have created. 2357 2363 for ( $i = 0; $i < 25; $i++ ) { 2358 2364 $wpdb->query( "ALTER TABLE `$table` DROP INDEX `{$index}_$i`" ); … … 2400 2406 } 2401 2407 2402 // Didn't find it try to create it.2408 // Didn't find it, so try to create it. 2403 2409 $wpdb->query( $create_ddl ); 2404 2410 … … 2567 2573 } 2568 2574 2569 // Separate individual queries into an array 2575 // Separate individual queries into an array. 2570 2576 if ( ! is_array( $queries ) ) { 2571 2577 $queries = explode( ';', $queries ); … … 2582 2588 $queries = apply_filters( 'dbdelta_queries', $queries ); 2583 2589 2584 $cqueries = array(); // Creation Queries2585 $iqueries = array(); // Insertion Queries2590 $cqueries = array(); // Creation queries. 2591 $iqueries = array(); // Insertion queries. 2586 2592 $for_update = array(); 2587 2593 2588 // Create a tablename index for an array ($cqueries) of queries 2594 // Create a tablename index for an array ($cqueries) of queries. 2589 2595 foreach ( $queries as $qry ) { 2590 2596 if ( preg_match( '|CREATE TABLE ([^ ]*)|', $qry, $matches ) ) { … … 2598 2604 $iqueries[] = $qry; 2599 2605 } else { 2600 // Unrecognized query type 2606 // Unrecognized query type. 2601 2607 } 2602 2608 } … … 2635 2641 } 2636 2642 2637 // Fetch the table column structure from the database 2643 // Fetch the table column structure from the database. 2638 2644 $suppress = $wpdb->suppress_errors(); 2639 2645 $tablefields = $wpdb->get_results( "DESCRIBE {$table};" ); … … 2783 2789 $tablefield_type_lowercased = strtolower( $tablefield->Type ); 2784 2790 2785 // If the table field exists in the field array 2791 // If the table field exists in the field array... 2786 2792 if ( array_key_exists( $tablefield_field_lowercased, $cfields ) ) { 2787 2793 … … 2808 2814 if ( $do_change ) { 2809 2815 // Add a query to change the column type. 2810 $cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN `{$tablefield->Field}` " . $cfields[ $tablefield_field_lowercased ]; 2816 $cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN `{$tablefield->Field}` " . $cfields[ $tablefield_field_lowercased ]; 2817 2811 2818 $for_update[ $table . '.' . $tablefield->Field ] = "Changed type of {$table}.{$tablefield->Field} from {$tablefield->Type} to {$fieldtype}"; 2812 2819 } … … 2818 2825 if ( $tablefield->Default != $default_value ) { 2819 2826 // Add a query to change the column's default value 2820 $cqueries[] = "ALTER TABLE {$table} ALTER COLUMN `{$tablefield->Field}` SET DEFAULT '{$default_value}'"; 2827 $cqueries[] = "ALTER TABLE {$table} ALTER COLUMN `{$tablefield->Field}` SET DEFAULT '{$default_value}'"; 2828 2821 2829 $for_update[ $table . '.' . $tablefield->Field ] = "Changed default value of {$table}.{$tablefield->Field} from {$tablefield->Default} to {$default_value}"; 2822 2830 } … … 2833 2841 foreach ( $cfields as $fieldname => $fielddef ) { 2834 2842 // Push a query line into $cqueries that adds the field to that table. 2835 $cqueries[] = "ALTER TABLE {$table} ADD COLUMN $fielddef"; 2843 $cqueries[] = "ALTER TABLE {$table} ADD COLUMN $fielddef"; 2844 2836 2845 $for_update[ $table . '.' . $fieldname ] = 'Added column ' . $table . '.' . $fieldname; 2837 2846 } … … 2846 2855 // For every index in the table. 2847 2856 foreach ( $tableindices as $tableindex ) { 2857 $keyname = strtolower( $tableindex->Key_name ); 2848 2858 2849 2859 // Add the index to the index data array. 2850 $keyname = strtolower( $tableindex->Key_name );2851 2860 $index_ary[ $keyname ]['columns'][] = array( 2852 2861 'fieldname' => $tableindex->Column_name, … … 2905 2914 foreach ( (array) $indices as $index ) { 2906 2915 // Push a query line into $cqueries that adds the index to that table. 2907 $cqueries[] = "ALTER TABLE {$table} ADD $index"; 2916 $cqueries[] = "ALTER TABLE {$table} ADD $index"; 2917 2908 2918 $for_update[] = 'Added index ' . $table . ' ' . $index; 2909 2919 } … … 3069 3079 3070 3080 // Copy files from the default theme to the site theme. 3071 // $files = array('index.php', 'comments.php', 'comments-popup.php', 'footer.php', 'header.php', 'sidebar.php', 'style.css');3081 // $files = array( 'index.php', 'comments.php', 'comments-popup.php', 'footer.php', 'header.php', 'sidebar.php', 'style.css' ); 3072 3082 3073 3083 $theme_dir = @opendir( $default_dir ); … … 3270 3280 global $wp_current_db_version, $wpdb; 3271 3281 3272 // Upgrade versions prior to 2.9 3282 // Upgrade versions prior to 2.9. 3273 3283 if ( $wp_current_db_version < 11557 ) { 3274 3284 // Delete duplicate options. Keep the option with the highest option_id. … … 3285 3295 if ( $wp_current_db_version < 25448 && is_multisite() && wp_should_upgrade_global_tables() ) { 3286 3296 3287 // Upgrade versions prior to 3.7 3297 // Upgrade versions prior to 3.7. 3288 3298 if ( $wp_current_db_version < 25179 ) { 3289 3299 // New primary key for signups. … … 3343 3353 ) $charset_collate; 3344 3354 "; 3345 // now create tables3355 // Now create tables. 3346 3356 dbDelta( $ms_queries ); 3347 3357 } … … 3368 3378 function wp_should_upgrade_global_tables() { 3369 3379 3370 // Return false early if explicitly not upgrading 3380 // Return false early if explicitly not upgrading. 3371 3381 if ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) { 3372 3382 return false; 3373 3383 } 3374 3384 3375 // Assume global tables should be upgraded 3385 // Assume global tables should be upgraded. 3376 3386 $should_upgrade = true; 3377 3387 3378 // Set to false if not on main network (does not matter if not multi-network) 3388 // Set to false if not on main network (does not matter if not multi-network). 3379 3389 if ( ! is_main_network() ) { 3380 3390 $should_upgrade = false; 3381 3391 } 3382 3392 3383 // Set to false if not on main site of current network (does not matter if not multi-site) 3393 // Set to false if not on main site of current network (does not matter if not multi-site). 3384 3394 if ( ! is_main_site() ) { 3385 3395 $should_upgrade = false;
Note: See TracChangeset
for help on using the changeset viewer.