Make option_name the primary key for the options table. Props Denis-de-Bernardy. fixes #2699
git-svn-id: https://develop.svn.wordpress.org/trunk@11883 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
d43ed9f448
commit
9ba99f344c
@ -99,8 +99,8 @@ CREATE TABLE $wpdb->options (
|
|||||||
option_name varchar(64) NOT NULL default '',
|
option_name varchar(64) NOT NULL default '',
|
||||||
option_value longtext NOT NULL,
|
option_value longtext NOT NULL,
|
||||||
autoload varchar(20) NOT NULL default 'yes',
|
autoload varchar(20) NOT NULL default 'yes',
|
||||||
PRIMARY KEY (option_id,blog_id,option_name),
|
PRIMARY KEY (option_name),
|
||||||
KEY option_name (option_name)
|
KEY option_id (option_id)
|
||||||
) $charset_collate;
|
) $charset_collate;
|
||||||
CREATE TABLE $wpdb->postmeta (
|
CREATE TABLE $wpdb->postmeta (
|
||||||
meta_id bigint(20) unsigned NOT NULL auto_increment,
|
meta_id bigint(20) unsigned NOT NULL auto_increment,
|
||||||
|
@ -269,6 +269,7 @@ function wp_upgrade() {
|
|||||||
|
|
||||||
wp_check_mysql_version();
|
wp_check_mysql_version();
|
||||||
wp_cache_flush();
|
wp_cache_flush();
|
||||||
|
pre_schema_upgrade();
|
||||||
make_db_current_silent();
|
make_db_current_silent();
|
||||||
upgrade_all();
|
upgrade_all();
|
||||||
wp_cache_flush();
|
wp_cache_flush();
|
||||||
@ -554,8 +555,10 @@ function upgrade_130() {
|
|||||||
if ( 1 != $option->dupes ) { // Could this be done in the query?
|
if ( 1 != $option->dupes ) { // Could this be done in the query?
|
||||||
$limit = $option->dupes - 1;
|
$limit = $option->dupes - 1;
|
||||||
$dupe_ids = $wpdb->get_col( $wpdb->prepare("SELECT option_id FROM $wpdb->options WHERE option_name = %s LIMIT %d", $option->option_name, $limit) );
|
$dupe_ids = $wpdb->get_col( $wpdb->prepare("SELECT option_id FROM $wpdb->options WHERE option_name = %s LIMIT %d", $option->option_name, $limit) );
|
||||||
$dupe_ids = join($dupe_ids, ',');
|
if ( $dupe_ids ) {
|
||||||
$wpdb->query("DELETE FROM $wpdb->options WHERE option_id IN ($dupe_ids)");
|
$dupe_ids = join($dupe_ids, ',');
|
||||||
|
$wpdb->query("DELETE FROM $wpdb->options WHERE option_id IN ($dupe_ids)");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1656,4 +1659,31 @@ function maybe_disable_automattic_widgets() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
/**
|
||||||
|
* Runs before the schema is upgraded.
|
||||||
|
*/
|
||||||
|
function pre_schema_upgrade() {
|
||||||
|
global $wp_current_db_version, $wp_db_version, $wpdb;
|
||||||
|
|
||||||
|
// Only run if less than 2.9
|
||||||
|
if ( $wp_current_db_version >= 11557 )
|
||||||
|
return;
|
||||||
|
|
||||||
|
// 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)");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add an index on option_id to satisfy the auto_increment requirement
|
||||||
|
$wpdb->query("ALTER TABLE $wpdb->options ADD INDEX option_id (option_id)");
|
||||||
|
|
||||||
|
// Drop the old primary key. The new primary will be created by dbDelta()
|
||||||
|
$wpdb->query("ALTER TABLE $wpdb->options DROP PRIMARY KEY");
|
||||||
|
|
||||||
|
// Drop the old option_name index. dbDelta() doesn't do the drop.
|
||||||
|
$wpdb->query("ALTER TABLE $wpdb->options DROP INDEX option_name");
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -621,8 +621,8 @@ function delete_option( $name ) {
|
|||||||
|
|
||||||
// Get the ID, if no ID then return
|
// Get the ID, if no ID then return
|
||||||
// expected_slashed ($name)
|
// expected_slashed ($name)
|
||||||
$option = $wpdb->get_row( "SELECT option_id, autoload FROM $wpdb->options WHERE option_name = '$name'" );
|
$option = $wpdb->get_row( "SELECT autoload FROM $wpdb->options WHERE option_name = '$name'" );
|
||||||
if ( is_null($option) || !$option->option_id )
|
if ( is_null($option) )
|
||||||
return false;
|
return false;
|
||||||
// expected_slashed ($name)
|
// expected_slashed ($name)
|
||||||
$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name = '$name'" );
|
$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name = '$name'" );
|
||||||
|
@ -15,7 +15,7 @@ $wp_version = '2.9-rare';
|
|||||||
*
|
*
|
||||||
* @global int $wp_db_version
|
* @global int $wp_db_version
|
||||||
*/
|
*/
|
||||||
$wp_db_version = 11548;
|
$wp_db_version = 11557;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the TinyMCE version
|
* Holds the TinyMCE version
|
||||||
|
Loading…
x
Reference in New Issue
Block a user