From 0c650d8a1a8942a67857410b87f9090cbbe3f0eb Mon Sep 17 00:00:00 2001 From: George Burduli Date: Tue, 16 Jul 2024 16:21:57 +0400 Subject: [PATCH 1/3] Replace $wpdb with OrdersTableDataStore util class --- modules/ppcp-compat/src/PPEC/PPECHelper.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/modules/ppcp-compat/src/PPEC/PPECHelper.php b/modules/ppcp-compat/src/PPEC/PPECHelper.php index a01c5eea7..6d9f81c27 100644 --- a/modules/ppcp-compat/src/PPEC/PPECHelper.php +++ b/modules/ppcp-compat/src/PPEC/PPECHelper.php @@ -7,6 +7,7 @@ namespace WooCommerce\PayPalCommerce\Compat\PPEC; +use Automattic\WooCommerce\Internal\DataStores\Orders\OrdersTableDataStore; use Automattic\WooCommerce\Utilities\OrderUtil; /** @@ -74,14 +75,17 @@ public static function site_has_ppec_subscriptions() { return $has_ppec_subscriptions === 'true'; } + $wc_orders_table = OrdersTableDataStore::get_orders_table_name(); + global $wpdb; - if ( class_exists( OrderUtil::class ) && OrderUtil::custom_orders_table_usage_is_enabled() && isset( $wpdb->wc_orders ) ) { - $result = $wpdb->get_var( - $wpdb->prepare( - "SELECT 1 FROM {$wpdb->wc_orders} WHERE payment_method = %s", - self::PPEC_GATEWAY_ID - ) + if ( $wc_orders_table && class_exists( OrderUtil::class ) && OrderUtil::custom_orders_table_usage_is_enabled() ) { + $query = $wpdb->prepare( + 'SELECT 1 FROM %s WHERE payment_method = %s', + $wc_orders_table, + self::PPEC_GATEWAY_ID ); + // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared + $result = $wpdb->get_var( $query ); } else { $result = $wpdb->get_var( $wpdb->prepare( From 741f3d06369f315f2bf20cfc0747705fa0238ddd Mon Sep 17 00:00:00 2001 From: George Burduli Date: Tue, 16 Jul 2024 17:41:08 +0400 Subject: [PATCH 2/3] Add OrdersTableDataStore psalm stub --- .psalm/stubs.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.psalm/stubs.php b/.psalm/stubs.php index 59be5215c..bc122164c 100644 --- a/.psalm/stubs.php +++ b/.psalm/stubs.php @@ -1,4 +1,6 @@ Date: Wed, 17 Jul 2024 11:00:39 +0400 Subject: [PATCH 3/3] Fix psalm stub --- .psalm/stubs.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/.psalm/stubs.php b/.psalm/stubs.php index bc122164c..e029868f5 100644 --- a/.psalm/stubs.php +++ b/.psalm/stubs.php @@ -1,6 +1,4 @@