From 02055537ac00c1f75995f9e50404bcb62973a8cd Mon Sep 17 00:00:00 2001 From: Michael Pretty Date: Fri, 17 Feb 2023 09:12:42 -0500 Subject: [PATCH] Switch to the use of dbDelta and truncate for the product attribute lookup tables over drop/create table. --- .../ProductAttributesLookup/DataRegenerator.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/plugins/woocommerce/src/Internal/ProductAttributesLookup/DataRegenerator.php b/plugins/woocommerce/src/Internal/ProductAttributesLookup/DataRegenerator.php index 6e613dbbd98..d88ea67b381 100644 --- a/plugins/woocommerce/src/Internal/ProductAttributesLookup/DataRegenerator.php +++ b/plugins/woocommerce/src/Internal/ProductAttributesLookup/DataRegenerator.php @@ -103,8 +103,9 @@ class DataRegenerator { delete_option( 'woocommerce_attribute_lookup_processed_count' ); $this->data_store->unset_regeneration_in_progress_flag(); - // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared - $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->lookup_table_name ); + if ( $this->data_store->check_lookup_table_exists() ) { + $wpdb->query( $wpdb->prepare( 'TRUNCATE TABLE %s', $this->lookup_table_name ) ); + } } /** @@ -114,10 +115,8 @@ class DataRegenerator { * @return bool True if there's any product at all in the database, false otherwise. */ private function initialize_table_and_data() { - global $wpdb; - - // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared - $wpdb->query( $this->get_table_creation_sql() ); + $database_util = wc_get_container()->get( DatabaseUtil::class ); + $database_util->dbdelta( $this->get_table_creation_sql() ); $last_existing_product_id = $this->get_last_existing_product_id(); if ( ! $last_existing_product_id ) {