Make WordPress Core


Ignore:
Timestamp:
12/18/2004 09:21:50 PM (20 years ago)
Author:
saxmatt
Message:

Delete duplicate options.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/upgrade-functions.php

    r1971 r1975  
    198198    $wpdb->query("UPDATE $wpdb->comments SET comment_type='pingback', comment_content = REPLACE(comment_content, '<pingback />', '') WHERE comment_content LIKE '<pingback />%'");
    199199
     200    // Some versions have multiple duplicate option_name rows with the same values
     201    $options = $wpdb->get_results("SELECT option_name, COUNT(option_name) AS dupes FROM `$wpdb->options` GROUP BY option_name");
     202    foreach ( $options as $option ) {
     203        if ( 1 != $option->dupes ) { // Could this be done in the query?
     204            $limit = $option->dupes - 1;
     205            $dupe_ids = $wpdb->get_col("SELECT option_id FROM $wpdb->options WHERE option_name = '$option->option_name' LIMIT $limit");
     206            $dupe_ids = join($dupe_ids, ',');
     207            $wpdb->query("DELETE FROM $wpdb->options WHERE option_id IN ($dupe_ids)");
     208        }
     209    }
    200210}
    201211
Note: See TracChangeset for help on using the changeset viewer.