Skip to content

Commit

Permalink
Jetpack Sync: Take order type into account when performing HPOS Check…
Browse files Browse the repository at this point in the history
…sums (#38688)

* Jetpack Sync: Take order type into account on HPOS Checksums

* changelog

* Fixup project versions

Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/10250840358

Upstream-Ref: Automattic/jetpack@01f5401
  • Loading branch information
darssen authored and matticbot committed Aug 5, 2024
1 parent 75648ff commit 4af8e95
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 99 deletions.
62 changes: 31 additions & 31 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/automattic/jetpack-blaze/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"automattic/jetpack-plans": "^0.4.7",
"automattic/jetpack-redirect": "^2.0.2",
"automattic/jetpack-status": "^3.3.2",
"automattic/jetpack-sync": "^3.4.0"
"automattic/jetpack-sync": "^3.4.1-alpha"
},
"require-dev": {
"yoast/phpunit-polyfills": "1.1.0",
Expand Down
8 changes: 8 additions & 0 deletions vendor/automattic/jetpack-sync/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.4.1-alpha] - unreleased

This is an alpha version! The changes listed here are not final.

### Fixed
- Jetpack Sync: Take order type into account when performing HPOS Checksums

## [3.4.0] - 2024-07-29
### Added
- Add support for syncing Jetpack WAF options. [#37957]
Expand Down Expand Up @@ -1219,6 +1226,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Packages: Move sync to a classmapped package

[3.4.1-alpha]: https://github.com/Automattic/jetpack-sync/compare/v3.4.0...v3.4.1-alpha
[3.4.0]: https://github.com/Automattic/jetpack-sync/compare/v3.3.1...v3.4.0
[3.3.1]: https://github.com/Automattic/jetpack-sync/compare/v3.3.0...v3.3.1
[3.3.0]: https://github.com/Automattic/jetpack-sync/compare/v3.2.1...v3.3.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
class Package_Version {

const PACKAGE_VERSION = '3.4.0';
const PACKAGE_VERSION = '3.4.1-alpha';

const PACKAGE_SLUG = 'sync';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,11 @@ public function __construct() {
/**
* Get order types that we want to sync. Adding a new type here is not enough, we would also need to add its prop in filter_order_data method.
*
* @access private
*
* @param bool $prefixed Whether to return prefixed types with shop_ or not.
*
* @return array Order types to sync.
*/
private function get_order_types_to_sync( $prefixed = false ) {
public static function get_order_types_to_sync( $prefixed = false ) {
$types = array( 'order', 'order_refund' );
if ( $prefixed ) {
$types = array_map(
Expand All @@ -87,7 +85,7 @@ function ( $type ) {
* @param callable $callable Action handler callable.
*/
public function init_listeners( $callable ) {
foreach ( $this->get_order_types_to_sync() as $type ) {
foreach ( self::get_order_types_to_sync() as $type ) {
add_action( "woocommerce_after_{$type}_object_save", $callable );
add_filter( "jetpack_sync_before_enqueue_woocommerce_after_{$type}_object_save", array( $this, 'expand_order_object' ) );
}
Expand Down Expand Up @@ -167,7 +165,7 @@ public function get_objects_by_id( $object_type, $ids ) {
$orders = wc_get_orders(
array(
'post__in' => $ids,
'type' => $this->get_order_types_to_sync( true ),
'type' => self::get_order_types_to_sync( true ),
'post_status' => $this->get_all_possible_order_status_keys(),
'limit' => -1,
)
Expand Down Expand Up @@ -420,7 +418,7 @@ public function enqueue_full_sync_actions( $config, $max_items_to_enqueue, $stat
public function get_where_sql( $config ) {
global $wpdb;
$parent_where = parent::get_where_sql( $config );
$order_types = $this->get_order_types_to_sync( true );
$order_types = self::get_order_types_to_sync( true );
$order_type_placeholder = implode( ', ', array_fill( 0, count( $order_types ), '%s' ) );
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare -- Query is prepared.
$where_sql = $wpdb->prepare( "type IN ( $order_type_placeholder )", $order_types );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Automattic\Jetpack\Sync\Replicastore;

use Automattic\Jetpack\Sync;
use Automattic\Jetpack\Sync\Modules\WooCommerce_HPOS_Orders;
use Exception;
use WP_Error;

Expand Down Expand Up @@ -312,14 +313,22 @@ protected function get_default_tables() {
'range_field' => 'id',
'key_fields' => array( 'id' ),
'checksum_text_fields' => array( 'type', 'status', 'payment_method_title' ),
'filter_values' => array(),
'filter_values' => array(
'type' => array(
'operator' => 'IN',
'values' => WooCommerce_HPOS_Orders::get_order_types_to_sync( true ),
),
),
'is_table_enabled_callback' => 'Automattic\Jetpack\Sync\Replicastore\Table_Checksum::enable_woocommerce_hpos_tables',
),
'wc_order_addresses' => array(
'table' => "{$wpdb->prefix}wc_order_addresses",
'range_field' => 'order_id',
'key_fields' => array( 'order_id', 'address_type' ),
'checksum_text_fields' => array( 'address_type' ),
'parent_table' => 'wc_orders',
'parent_join_field' => 'id',
'table_join_field' => 'order_id',
'filter_values' => array(),
'is_table_enabled_callback' => 'Automattic\Jetpack\Sync\Replicastore\Table_Checksum::enable_woocommerce_hpos_tables',
),
Expand All @@ -328,6 +337,9 @@ protected function get_default_tables() {
'range_field' => 'order_id',
'key_fields' => array( 'order_id' ),
'checksum_text_fields' => array( 'order_key', 'cart_hash' ),
'parent_table' => 'wc_orders',
'parent_join_field' => 'id',
'table_join_field' => 'order_id',
'filter_values' => array(),
'is_table_enabled_callback' => 'Automattic\Jetpack\Sync\Replicastore\Table_Checksum::enable_woocommerce_hpos_tables',
),
Expand Down
Loading

0 comments on commit 4af8e95

Please sign in to comment.