Support hosts which do not have access to 'DUAL' table (#39111)

This commit is contained in:
Barry Hughes 2023-07-07 05:32:42 -07:00 committed by GitHub
commit f58580452c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: tweak
Use existing table instead of 'DUAL' to support hosts which do not support 'DUAL'.

View File

@ -532,16 +532,16 @@ class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Dat
);
$query_for_tentative_usages = $this->get_tentative_usage_query( $coupon->get_id() );
$db_timestamp = $wpdb->get_var( 'SELECT UNIX_TIMESTAMP() FROM DUAL' );
$db_timestamp = $wpdb->get_var( 'SELECT UNIX_TIMESTAMP() FROM ' . $wpdb->posts . ' LIMIT 1' );
$coupon_usage_key = '_coupon_held_' . ( (int) $db_timestamp + $held_time ) . '_' . wp_generate_password( 6, false );
$insert_statement = $wpdb->prepare(
"
INSERT INTO $wpdb->postmeta ( post_id, meta_key, meta_value )
SELECT %d, %s, %s FROM DUAL
SELECT %d, %s, %s FROM $wpdb->posts
WHERE ( $query_for_usages ) + ( $query_for_tentative_usages ) < %d
",
LIMIT 1",
$coupon->get_id(),
$coupon_usage_key,
'',
@ -629,15 +629,15 @@ class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Dat
); // WPCS: unprepared SQL ok.
$query_for_tentative_usages = $this->get_tentative_usage_query_for_user( $coupon->get_id(), $user_aliases );
$db_timestamp = $wpdb->get_var( 'SELECT UNIX_TIMESTAMP() FROM DUAL' );
$db_timestamp = $wpdb->get_var( 'SELECT UNIX_TIMESTAMP() FROM ' . $wpdb->posts . ' LIMIT 1' );
$coupon_used_by_meta_key = '_maybe_used_by_' . ( (int) $db_timestamp + $held_time ) . '_' . wp_generate_password( 6, false );
$insert_statement = $wpdb->prepare(
"
INSERT INTO $wpdb->postmeta ( post_id, meta_key, meta_value )
SELECT %d, %s, %s FROM DUAL
SELECT %d, %s, %s FROM $wpdb->posts
WHERE ( $query_for_usages ) + ( $query_for_tentative_usages ) < %d
",
LIMIT 1",
$coupon->get_id(),
$coupon_used_by_meta_key,
$user_alias,