Correct table names and updater

This commit is contained in:
Mike Jolley 2019-02-12 14:04:22 +00:00
parent ac51d1f1df
commit 7b6558e1df
6 changed files with 35 additions and 31 deletions

View File

@ -650,6 +650,8 @@ class WC_Install {
$collate = $wpdb->get_charset_collate();
}
$price_decimals = max( 2, absint( wc_get_price_decimals() ) );
$tables = "
CREATE TABLE {$wpdb->prefix}woocommerce_sessions (
session_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
@ -825,14 +827,14 @@ CREATE TABLE {$wpdb->prefix}wc_download_log (
) $collate;
CREATE TABLE {$wpdb->prefix}wc_product_sorting (
`product_id` bigint(20) NOT NULL,
`price` double NULL default NULL,
`min_price` double NULL default NULL,
`max_price` double NULL default NULL,
`average_rating` float NULL default 0,
`total_sales` double NULL default 0,
`price` decimal(10,{$price_decimals}) NULL default NULL,
`min_price` decimal(10,{$price_decimals}) NULL default NULL,
`max_price` decimal(10,{$price_decimals}) NULL default NULL,
`average_rating` decimal(10,2) NULL default 0,
`total_sales` bigint(20) NULL default 0,
PRIMARY KEY (`product_id`),
KEY product_id_price (`product_id`,`max_price`,`min_price`)
KEY product_id_average_rating (`product_id`,`average_rating`)
KEY product_id_price (`product_id`,`max_price`,`min_price`),
KEY product_id_average_rating (`product_id`,`average_rating`),
KEY product_id_total_sales (`product_id`,`total_sales`)
) $collate;
";

View File

@ -500,7 +500,7 @@ class WC_Query {
}
/**
* Custom query used to filter products by price from the wc_product_sorting table.
* Custom query used to filter products by price.
*
* @since 3.6.0
*
@ -610,7 +610,7 @@ class WC_Query {
global $wpdb;
if ( ! strstr( $sql, 'wc_product_sorting' ) ) {
$sql .= " LEFT JOIN {$wpdb->prefix}wc_product_sorting wc_product_sorting ON $wpdb->posts.ID = wc_product_sorting.product_id ";
$sql .= " LEFT JOIN {$wpdb->wc_product_sorting} wc_product_sorting ON $wpdb->posts.ID = wc_product_sorting.product_id ";
}
return $sql;
}

View File

@ -648,15 +648,20 @@ final class WooCommerce {
}
/**
* WooCommerce Payment Token Meta API and Term/Order item Meta - set table names.
* Set tablenames inside WPDB object.
*/
public function wpdb_table_fix() {
global $wpdb;
$wpdb->payment_tokenmeta = $wpdb->prefix . 'woocommerce_payment_tokenmeta';
$wpdb->order_itemmeta = $wpdb->prefix . 'woocommerce_order_itemmeta';
$wpdb->tables[] = 'woocommerce_payment_tokenmeta';
$wpdb->order_itemmeta = $wpdb->prefix . 'woocommerce_order_itemmeta';
$wpdb->tables[] = 'woocommerce_order_itemmeta';
$wpdb->wc_product_sorting = $wpdb->prefix . 'wc_product_sorting';
$wpdb->tables[] = 'wc_product_sorting';
if ( get_option( 'db_version' ) < 34370 ) {
$wpdb->woocommerce_termmeta = $wpdb->prefix . 'woocommerce_termmeta';
$wpdb->tables[] = 'woocommerce_termmeta';

View File

@ -534,7 +534,7 @@ class WC_Data_Store_WP {
if ( ! empty( $update_data ) && $update_data !== $existing_data ) {
$wpdb->replace(
$wpdb->prefix . $table,
$wpdb->$table,
$update_data
);
wp_cache_set( 'lookup_table', $update_data, 'object_' . $id );

View File

@ -1274,9 +1274,8 @@ function wc_update_product_lookup_tables() {
global $wpdb;
$result = $wpdb->query(
$wpdb->prepare(
"
INSERT IGNORE INTO {$wpdb->prefix}wc_product_sorting (`product_id`, `price`, `min_price`, `max_price`, `average_rating`, `total_sales`)
INSERT IGNORE INTO {$wpdb->wc_product_sorting} (`product_id`, `price`, `min_price`, `max_price`, `average_rating`, `total_sales`)
SELECT posts.ID, MIN(meta1.meta_value), MIN(meta1.meta_value), MAX(meta1.meta_value), meta2.meta_value, meta3.meta_value
FROM {$wpdb->posts} posts
LEFT JOIN {$wpdb->postmeta} meta1 ON posts.ID = meta1.post_id
@ -1288,8 +1287,6 @@ function wc_update_product_lookup_tables() {
AND meta2.meta_key = '_wc_average_rating'
AND meta3.meta_key = 'total_sales'
GROUP BY posts.ID
",
$default_category
)
"
);
}

View File

@ -151,7 +151,7 @@ class WC_Widget_Price_Filter extends WC_Widget {
$sql = "
SELECT min( min_price ) as min_price, MAX( max_price ) as max_price
FROM {$wpdb->prefix}wc_product_sorting
FROM {$wpdb->wc_product_sorting}
WHERE product_id IN (
SELECT ID FROM {$wpdb->posts}
" . $tax_query_sql['join'] . $meta_query_sql['join'] . "