$wpdb; $collate = $wpdb->has_cap( 'collation' ) ? $wpdb->get_charset_collate() : ''; return "CREATE TABLE {$this->lookup_table_name} ( product_id bigint(20) NOT NULL, product_or_parent_id bigint(20) NOT NULL, taxonomy varchar(32) NOT NULL, term_id bigint(20) NOT NULL, is_variation_attribute tinyint(1) NOT NULL, in_stock tinyint(1) NOT NULL, INDEX is_variation_attribute_term_id (is_variation_attribute, term_id), INDEX taxonomy_term_id_in_stock_product_or_parent_id (taxonomy, term_id, in_stock, product_or_parent_id), PRIMARY KEY ( `product_or_parent_id`, `term_id`, `product_id`, `taxonomy` ), KEY product_id (product_id) ) $collate;"; } /** * Create the primary key for the table if it doesn't exist already. * It also deletes the product_or_parent_id_term_id index if it exists, since it's now redundant. * * @return void */ public function create_table_primary_index() { $database_util = wc_get_container()->get( DatabaseUtil::class ); $database_util->create_primary_key( $this->lookup_table_name, array( 'product_or_parent_id', 'term_id', 'product_id', 'taxonomy' ) ); $database_util->drop_table_index( $this->lookup_table_name, 'product_or_parent_id_term_id' ); if ( empty( $database_util->get_index_columns( $this->lookup_table_name ) ) ) { wc_get_logger()->error( "The creation of the primary key for the {$this->lookup_table_name} table failed" ); } if ( ! empty( $database_util->get_index_columns( $this->lookup_table_name, 'product_or_parent_id_term_id' ) ) ) { wc_get_logger()->error( "Dropping the product_or_parent_id_term_id index from the {$this->lookup_table_name} table failed" ); } } /** * Run additional setup needed after a WooCommerce install or update finishes. * * @internal For exclusive usage of WooCommerce core, backwards compatibility not guaranteed. */ public function run_woocommerce_installed_callback() { // The table must exist at this point (created via dbDelta), but we check just in case. if ( ! $this->data_store->check_lookup_table_exists() ) { return; } // If a table regeneration is in progress, leave it alone. if ( $this->data_store->regeneration_is_in_progress() ) { return; } // If the lookup table has data, or if it's empty because there are no products yet, we're good. // Otherwise (lookup table is empty but products exist) we need to initiate a regeneration if one isn't already in progress. if ( $this->data_store->lookup_table_has_data() || ! $this->get_last_existing_product_id() ) { $must_enable = get_option( 'woocommerce_attribute_lookup_enabled' ) !== 'no'; $this->delete_all_attributes_lookup_data( false ); update_option( 'woocommerce_attribute_lookup_enabled', $must_enable ? 'yes' : 'no' ); } else { $this->initiate_regeneration(); } } }