From 736b9d8bcbbf501a4db76020759b701dd8e4c454 Mon Sep 17 00:00:00 2001 From: saxmatt Date: Sat, 18 Dec 2004 21:21:50 +0000 Subject: [PATCH] Delete duplicate options. git-svn-id: http://svn.automattic.com/wordpress/trunk@1975 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/upgrade-functions.php | 10 ++++++++++ wp-admin/upgrade-schema.php | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/wp-admin/upgrade-functions.php b/wp-admin/upgrade-functions.php index 8b19d00d09..952654b9ce 100644 --- a/wp-admin/upgrade-functions.php +++ b/wp-admin/upgrade-functions.php @@ -197,6 +197,16 @@ function upgrade_130() { $wpdb->query("UPDATE $wpdb->comments SET comment_type='trackback', comment_content = REPLACE(comment_content, '', '') WHERE comment_content LIKE '%'"); $wpdb->query("UPDATE $wpdb->comments SET comment_type='pingback', comment_content = REPLACE(comment_content, '', '') WHERE comment_content LIKE '%'"); + // Some versions have multiple duplicate option_name rows with the same values + $options = $wpdb->get_results("SELECT option_name, COUNT(option_name) AS dupes FROM `$wpdb->options` GROUP BY option_name"); + foreach ( $options as $option ) { + if ( 1 != $option->dupes ) { // Could this be done in the query? + $limit = $option->dupes - 1; + $dupe_ids = $wpdb->get_col("SELECT option_id FROM $wpdb->options WHERE option_name = '$option->option_name' LIMIT $limit"); + $dupe_ids = join($dupe_ids, ','); + $wpdb->query("DELETE FROM $wpdb->options WHERE option_id IN ($dupe_ids)"); + } + } } // The functions we use to actually do stuff diff --git a/wp-admin/upgrade-schema.php b/wp-admin/upgrade-schema.php index 151351a471..a3e3c80887 100644 --- a/wp-admin/upgrade-schema.php +++ b/wp-admin/upgrade-schema.php @@ -78,7 +78,8 @@ CREATE TABLE $wpdb->options ( option_description tinytext NOT NULL, option_admin_level int(11) NOT NULL default '1', autoload enum('yes','no') NOT NULL default 'yes', - PRIMARY KEY (option_id,blog_id,option_name) + PRIMARY KEY (option_id,blog_id,option_name), + KEY option_name (option_name) ); CREATE TABLE $wpdb->post2cat ( rel_id int(11) NOT NULL auto_increment,