WordPress.org

Make WordPress Core

Ticket #2699: 2699.3.diff

File 2699.3.diff, 4.3 KB (added by Denis-de-Bernardy, 5 years ago)

same the previous patch, but deprecate option_id as the same time

  • wp-includes/version.php

     
    1515 * 
    1616 * @global int $wp_db_version 
    1717 */ 
    18 $wp_db_version = 11548; 
     18$wp_db_version = 11557; 
    1919 
    2020/** 
    2121 * Holds the TinyMCE version 
  • wp-includes/functions.php

     
    621621 
    622622        // Get the ID, if no ID then return 
    623623        // expected_slashed ($name) 
    624         $option = $wpdb->get_row( "SELECT option_id, autoload FROM $wpdb->options WHERE option_name = '$name'" ); 
    625         if ( is_null($option) || !$option->option_id ) 
     624        $option = $wpdb->get_row( "SELECT autoload FROM $wpdb->options WHERE option_name = '$name'" ); 
     625        if ( is_null($option) ) 
    626626                return false; 
    627627        // expected_slashed ($name) 
    628628        $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name = '$name'" ); 
  • wp-settings.php

     
    262262 */ 
    263263$wpdb->field_types = array( 'post_author' => '%d', 'post_parent' => '%d', 'menu_order' => '%d', 'term_id' => '%d', 'term_group' => '%d', 'term_taxonomy_id' => '%d', 
    264264        'parent' => '%d', 'count' => '%d','object_id' => '%d', 'term_order' => '%d', 'ID' => '%d', 'commment_ID' => '%d', 'comment_post_ID' => '%d', 'comment_parent' => '%d', 
    265         'user_id' => '%d', 'link_id' => '%d', 'link_owner' => '%d', 'link_rating' => '%d', 'option_id' => '%d', 'blog_id' => '%d', 'meta_id' => '%d', 'post_id' => '%d', 
     265        'user_id' => '%d', 'link_id' => '%d', 'link_owner' => '%d', 'link_rating' => '%d', 'blog_id' => '%d', 'meta_id' => '%d', 'post_id' => '%d', 
    266266        'user_status' => '%d', 'umeta_id' => '%d', 'comment_karma' => '%d', 'comment_count' => '%d'); 
    267267 
    268268$prefix = $wpdb->set_prefix($table_prefix); 
  • wp-admin/includes/upgrade.php

     
    269269 
    270270        wp_check_mysql_version(); 
    271271        wp_cache_flush(); 
     272        pre_schema_upgrade(); 
    272273        make_db_current_silent(); 
    273274        upgrade_all(); 
    274275        wp_cache_flush(); 
     
    554555                if ( 1 != $option->dupes ) { // Could this be done in the query? 
    555556                        $limit = $option->dupes - 1; 
    556557                        $dupe_ids = $wpdb->get_col( $wpdb->prepare("SELECT option_id FROM $wpdb->options WHERE option_name = %s LIMIT %d", $option->option_name, $limit) ); 
    557                         $dupe_ids = join($dupe_ids, ','); 
    558                         $wpdb->query("DELETE FROM $wpdb->options WHERE option_id IN ($dupe_ids)"); 
     558                        if ( $dupe_ids ) { 
     559                                $dupe_ids = join($dupe_ids, ','); 
     560                                $wpdb->query("DELETE FROM $wpdb->options WHERE option_id IN ($dupe_ids)"); 
     561                        } 
    559562                } 
    560563        } 
    561564 
     
    16561659        } 
    16571660} 
    16581661 
    1659 ?> 
     1662/** 
     1663 * Runs before the schema is upgraded. 
     1664 */ 
     1665function pre_schema_upgrade() { 
     1666        global $wp_current_db_version, $wp_db_version, $wpdb; 
     1667 
     1668        // Only run if less than 2.9 
     1669        if ( $wp_current_db_version >= 11557 ) 
     1670                return; 
     1671 
     1672        // Delete duplicate options.  Keep the option with the highest option_id. 
     1673        $delete_options = $wpdb->get_col("SELECT o1.option_id FROM wp_options AS o1 JOIN wp_options AS o2 ON o2.option_name = o1.option_name AND o2.option_id > o1.option_id"); 
     1674        if ( empty($delete_options) ) 
     1675                return; 
     1676 
     1677        $delete_options = implode("', '", $delete_options); 
     1678        $wpdb->query("DELETE FROM $wpdb->options WHERE option_id IN ($delete_options)"); 
     1679} 
     1680 
     1681?> 
     1682 No newline at end of file 
  • wp-admin/includes/schema.php

     
    9494  KEY link_visible (link_visible) 
    9595) $charset_collate; 
    9696CREATE TABLE $wpdb->options ( 
    97   option_id bigint(20) unsigned NOT NULL auto_increment, 
    98   blog_id int(11) NOT NULL default '0', 
    9997  option_name varchar(64) NOT NULL default '', 
    10098  option_value longtext NOT NULL, 
    10199  autoload varchar(20) NOT NULL default 'yes', 
    102   PRIMARY KEY  (option_id,blog_id,option_name), 
    103   KEY option_name (option_name) 
     100  PRIMARY KEY  (option_name) 
    104101) $charset_collate; 
    105102CREATE TABLE $wpdb->postmeta ( 
    106103  meta_id bigint(20) unsigned NOT NULL auto_increment,