Merge pull request #21561 from woocommerce/fix/21534

Improve session table update routine
This commit is contained in:
Claudiu Lodromanean 2018-10-15 09:47:41 -07:00 committed by GitHub
commit c3bf253a88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 3 deletions

View File

@ -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`)"
);
}
}
/**