Skip to content

Commit

Permalink
Better duplicate option delete query. Props miqrogroove. fixes #11649…
Browse files Browse the repository at this point in the history
… for 2.9

git-svn-id: http://svn.automattic.com/wordpress/branches/2.9@12561 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
ryan committed Dec 28, 2009
1 parent f7b0a05 commit a7632b6
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions wp-admin/includes/upgrade.php
Expand Up @@ -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)");
Expand Down

0 comments on commit a7632b6

Please sign in to comment.