Permalink
Browse files

Better duplicate option delete query. Props miqrogroove. fixes #11649…

… for 2.9

git-svn-id: http://svn.automattic.com/wordpress/branches/2.9@12561 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information...
1 parent f7b0a05 commit a7632b611eaa88b4aceb021933b2c78ff6c76b36 ryan committed Dec 28, 2009
Showing with 1 addition and 5 deletions.
  1. +1 −5 wp-admin/includes/upgrade.php
@@ -1688,11 +1688,7 @@ function pre_schema_upgrade() {
// Upgrade versions prior to 2.9
if ( $wp_current_db_version < 11557 ) {
// Delete duplicate options. Keep the option with the highest option_id.
- $delete_options = $wpdb->get_col("SELECT o1.option_id FROM $wpdb->options AS o1 JOIN $wpdb->options AS o2 ON o2.option_name = o1.option_name AND o2.option_id > o1.option_id");
- if ( !empty($delete_options) ) {
- $delete_options = implode(',', $delete_options);
- $wpdb->query("DELETE FROM $wpdb->options WHERE option_id IN ($delete_options)");
- }
+ $wpdb->query("DELETE o1 FROM $wpdb->options AS o1 JOIN $wpdb->options AS o2 USING (`option_name`) WHERE o2.option_id > o1.option_id");
// Drop the old primary key and add the new.
$wpdb->query("ALTER TABLE $wpdb->options DROP PRIMARY KEY, ADD PRIMARY KEY(option_id)");

0 comments on commit a7632b6

Please sign in to comment.