Merge pull request #23455 from woocommerce/update/23388
During initial product lookup table generation, set an option
This commit is contained in:
commit
b2e428d4cc
|
@ -486,14 +486,14 @@ class WC_Product_Variable_Data_Store_CPT extends WC_Product_Data_Store_CPT imple
|
|||
$query_in = '(' . implode( ',', $format ) . ')';
|
||||
$query_args = array( 'stock_status' => $status ) + $children;
|
||||
// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared
|
||||
if ( get_option( 'woocommerce_product_lookup_table_is_generating' ) ) {
|
||||
$query = "SELECT COUNT( post_id ) FROM {$wpdb->postmeta} WHERE meta_key = '_stock_status' AND meta_value = %s AND post_id IN {$query_in}";
|
||||
} else {
|
||||
$query = "SELECT COUNT( product_id ) FROM {$wpdb->wc_product_meta_lookup} WHERE stock_status = %s AND product_id IN {$query_in}";
|
||||
}
|
||||
$children_with_status = $wpdb->get_var(
|
||||
$wpdb->prepare(
|
||||
"
|
||||
SELECT COUNT( product_id )
|
||||
FROM {$wpdb->wc_product_meta_lookup}
|
||||
WHERE stock_status = %s
|
||||
AND product_id IN {$query_in}
|
||||
",
|
||||
$query,
|
||||
$query_args
|
||||
)
|
||||
);
|
||||
|
|
|
@ -1302,6 +1302,9 @@ function wc_update_product_lookup_tables() {
|
|||
WC_Admin_Notices::add_notice( 'regenerating_lookup_table' );
|
||||
}
|
||||
|
||||
// Note that the table is not yet generated.
|
||||
update_option( 'woocommerce_product_lookup_table_is_generating', true );
|
||||
|
||||
// Make a row per product in lookup table.
|
||||
$wpdb->query(
|
||||
"
|
||||
|
@ -1324,7 +1327,7 @@ function wc_update_product_lookup_tables() {
|
|||
'total_sales',
|
||||
'downloadable',
|
||||
'virtual',
|
||||
'onsale',
|
||||
'onsale', // When last column is updated, woocommerce_product_lookup_table_is_generating is updated.
|
||||
);
|
||||
|
||||
foreach ( $columns as $index => $column ) {
|
||||
|
@ -1482,6 +1485,8 @@ function wc_update_product_lookup_tables_column( $column ) {
|
|||
$decimals
|
||||
)
|
||||
);
|
||||
|
||||
delete_option( 'woocommerce_product_lookup_table_is_generating' ); // Complete.
|
||||
break;
|
||||
}
|
||||
// phpcs:enable WordPress.DB.PreparedSQL.NotPrepared
|
||||
|
|
Loading…
Reference in New Issue