Check if there is a comment_type index before adding one

Adding this check to avoid a MySQL error when running the query if the index already exists.
This commit is contained in:
Rodrigo Primo 2016-08-09 14:28:41 +02:00
parent 2e8f02f6a4
commit 7acf712e45
1 changed files with 7 additions and 3 deletions

View File

@ -404,9 +404,13 @@ class WC_Install {
dbDelta( self::get_schema() ); dbDelta( self::get_schema() );
// Add an index to the field comment_type to improve the response time of the query $index_exists = $wpdb->get_row( "SHOW INDEX FROM {$wpdb->comments} WHERE Column_name = 'comment_type' and Key_name = 'comment_type'" );
// used by WC_Comments::wp_count_comments() to get the number of comments by type.
$wpdb->query( "ALTER TABLE {$wpdb->comments} ADD INDEX woo_idx_comment_type (comment_type)" ); if ( is_null( $index_exists ) ) {
// Add an index to the field comment_type to improve the response time of the query
// used by WC_Comments::wp_count_comments() to get the number of comments by type.
$wpdb->query( "ALTER TABLE {$wpdb->comments} ADD INDEX woo_idx_comment_type (comment_type)" );
}
} }
/** /**