| 1660 | /** |
| 1661 | * Runs before the schema is upgraded. |
| 1662 | */ |
| 1663 | function 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 | |