WordPress.org

Make WordPress Core

Ticket #2699: 2699.diff

File 2699.diff, 2.1 KB (added by ryan, 9 years ago)
  • 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-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();
     
    16561657        }
    16571658}
    16581659
     1660/**
     1661 * Runs before the schema is upgraded.
     1662 */
     1663function pre_schema_upgrade() {
     1664        global $wp_current_db_version, $wp_db_version, $wpdb;
     1665
     1666        // Only run if less than 2.9
     1667        if ( $wp_current_db_version >= 11557 )
     1668                return;
     1669
     1670        // Delete duplicate options.  Keep the option with the highest option_id.
     1671        $options = $wpdb->get_results("SELECT option_name, option_id FROM $wpdb->options ORDER BY option_id DESC");
     1672        $seen_options = array();
     1673        $delete_options = array();
     1674        foreach ($options as $option) {
     1675                if ( isset( $seen_options[$option->option_name] ) ) {
     1676                        $delete_options[] = $option->option_id;
     1677                        wp_cache_delete($option->option_name, 'options');
     1678                } else {
     1679                        $seen_options[$option->option_name] = true;
     1680                }
     1681        }
     1682
     1683        if ( empty($delete_options) )
     1684                return;
     1685
     1686        $delete_options = implode("', '", $delete_options);
     1687        $wpdb->query("DELETE FROM $wpdb->options WHERE option_id IN ($delete_options)");
     1688}
     1689
    16591690?>
  • wp-admin/includes/schema.php

     
    100100  option_value longtext NOT NULL,
    101101  autoload varchar(20) NOT NULL default 'yes',
    102102  PRIMARY KEY  (option_id,blog_id,option_name),
    103   KEY option_name (option_name)
     103  UNIQUE KEY name (option_name)
    104104) $charset_collate;
    105105CREATE TABLE $wpdb->postmeta (
    106106  meta_id bigint(20) unsigned NOT NULL auto_increment,