Merge pull request #21561 from woocommerce/fix/21534
Improve session table update routine
This commit is contained in:
commit
c3bf253a88
|
@ -1999,9 +1999,20 @@ function wc_update_350_reviews_comment_type() {
|
|||
function wc_update_350_change_woocommerce_sessions_schema() {
|
||||
global $wpdb;
|
||||
|
||||
$wpdb->query(
|
||||
"ALTER TABLE `{$wpdb->prefix}woocommerce_sessions` DROP PRIMARY KEY, DROP KEY `session_id`, ADD PRIMARY KEY(`session_id`), ADD UNIQUE KEY(`session_key`)"
|
||||
);
|
||||
$results = $wpdb->get_results( "
|
||||
SELECT CONSTRAINT_NAME
|
||||
FROM information_schema.TABLE_CONSTRAINTS
|
||||
WHERE CONSTRAINT_SCHEMA = '{$wpdb->dbname}'
|
||||
AND CONSTRAINT_TYPE = 'UNIQUE'
|
||||
AND CONSTRAINT_NAME = 'session_key'
|
||||
AND TABLE_NAME = '{$wpdb->prefix}woocommerce_sessions'
|
||||
" );
|
||||
|
||||
if ( ! $results ) {
|
||||
$wpdb->query(
|
||||
"ALTER TABLE `{$wpdb->prefix}woocommerce_sessions` DROP KEY `session_id`, ADD UNIQUE KEY(`session_key`)"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue