diff --git a/plugins/woocommerce/src/Internal/DataStores/Orders/CustomOrdersTableController.php b/plugins/woocommerce/src/Internal/DataStores/Orders/CustomOrdersTableController.php index 8fb36b9f5ec..4fc9076f9e8 100644 --- a/plugins/woocommerce/src/Internal/DataStores/Orders/CustomOrdersTableController.php +++ b/plugins/woocommerce/src/Internal/DataStores/Orders/CustomOrdersTableController.php @@ -11,7 +11,6 @@ use Automattic\WooCommerce\Caches\OrderCacheController; use Automattic\WooCommerce\Internal\BatchProcessing\BatchProcessingController; use Automattic\WooCommerce\Internal\Features\FeaturesController; use Automattic\WooCommerce\Internal\Traits\AccessiblePrivateMethods; -use Automattic\WooCommerce\Utilities\OrderUtil; use Automattic\WooCommerce\Utilities\PluginUtil; defined( 'ABSPATH' ) || exit; @@ -118,7 +117,7 @@ class CustomOrdersTableController { self::add_filter( 'woocommerce_debug_tools', array( $this, 'add_initiate_regeneration_entry_to_tools_array' ), 999, 1 ); self::add_filter( 'updated_option', array( $this, 'process_updated_option' ), 999, 3 ); self::add_filter( 'pre_update_option', array( $this, 'process_pre_update_option' ), 999, 3 ); - self::add_action( 'woocommerce_update_options_advanced_custom_data_stores', array( $this, 'process_options_updated' ), 10, 0 ); + self::add_action( FeaturesController::FEATURE_ENABLED_CHANGED_ACTION, array( $this, 'process_options_updated' ), 10, 1 ); self::add_action( 'woocommerce_after_register_post_type', array( $this, 'register_post_type_for_order_placeholders' ), 10, 0 ); self::add_action( FeaturesController::FEATURE_ENABLED_CHANGED_ACTION, array( $this, 'handle_feature_enabled_changed' ), 10, 2 ); self::add_action( 'woocommerce_feature_setting', array( $this, 'get_hpos_feature_setting' ), 10, 2 ); @@ -356,8 +355,13 @@ class CustomOrdersTableController { /** * Handler for the all settings updated hook. + * + * @param string $feature_id Feature ID. */ - private function process_options_updated() { + private function process_options_updated( string $feature_id ) { + if ( DataSynchronizer::ORDERS_DATA_SYNC_ENABLED_OPTION !== $feature_id ) { + return; + } $data_sync_is_enabled = $this->data_synchronizer->data_sync_is_enabled(); // Enabling/disabling the sync implies starting/stopping it too, if needed. @@ -454,10 +458,10 @@ class CustomOrdersTableController { */ private function get_hpos_setting_for_feature( $sync_status ) { $hpos_enabled = $this->custom_orders_table_usage_is_enabled(); - $plugin_info = $this->features_controller->get_compatible_plugins_for_feature( 'custom_order_tables' ); + $plugin_info = $this->features_controller->get_compatible_plugins_for_feature( 'custom_order_tables', true ); $plugin_incompat_warning = $this->plugin_util->generate_incompatible_plugin_feature_warning( 'custom_order_tables', $plugin_info ); $sync_complete = 0 === $sync_status['current_pending_count']; - $can_hpos_enabled = count( array_merge( $plugin_info['compatible'], $plugin_info['incompatible'] ) ) === 0; + $can_hpos_enabled = count( array_merge( $plugin_info['uncertain'], $plugin_info['incompatible'] ) ) === 0; return array( 'id' => self::CUSTOM_ORDERS_TABLE_USAGE_ENABLED_OPTION, @@ -468,7 +472,7 @@ class CustomOrdersTableController { 'yes' => __( 'High performance order storage (new)', 'woocommerce' ), ), 'value' => $hpos_enabled ? 'yes' : 'no', - 'disabled' => $can_hpos_enabled && $sync_complete ? array() : array( 'yes' ), + 'disabled' => $can_hpos_enabled && $sync_complete ? array() : array( 'yes', 'no' ), 'desc' => $plugin_incompat_warning, 'desc_at_end' => true, ); diff --git a/plugins/woocommerce/src/Internal/DataStores/Orders/DataSynchronizer.php b/plugins/woocommerce/src/Internal/DataStores/Orders/DataSynchronizer.php index f990ee453a1..d116d71b6db 100644 --- a/plugins/woocommerce/src/Internal/DataStores/Orders/DataSynchronizer.php +++ b/plugins/woocommerce/src/Internal/DataStores/Orders/DataSynchronizer.php @@ -28,7 +28,6 @@ class DataSynchronizer implements BatchProcessorInterface { public const ORDERS_DATA_SYNC_ENABLED_OPTION = 'woocommerce_custom_orders_table_data_sync_enabled'; private const INITIAL_ORDERS_PENDING_SYNC_COUNT_OPTION = 'woocommerce_initial_orders_pending_sync_count'; - public const PENDING_SYNCHRONIZATION_FINISHED_ACTION = 'woocommerce_orders_sync_finished'; public const PLACEHOLDER_ORDER_POST_TYPE = 'shop_order_placehold'; public const DELETED_RECORD_META_KEY = '_deleted_from'; diff --git a/plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableDataStore.php b/plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableDataStore.php index 6b3225e4461..3bc06c6ac07 100644 --- a/plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableDataStore.php +++ b/plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableDataStore.php @@ -1050,7 +1050,7 @@ WHERE return; } - $data_sync_enabled = $data_synchronizer->data_sync_is_enabled() && 0 === $data_synchronizer->get_current_orders_pending_sync_count_cached(); + $data_sync_enabled = $data_synchronizer->data_sync_is_enabled(); $load_posts_for = array_diff( $order_ids, self::$reading_order_ids ); $post_orders = $data_sync_enabled ? $this->get_post_orders_for_ids( array_intersect_key( $orders, array_flip( $load_posts_for ) ) ) : array(); diff --git a/plugins/woocommerce/src/Internal/Features/FeaturesController.php b/plugins/woocommerce/src/Internal/Features/FeaturesController.php index 49bbfceb544..c6fe7503ad2 100644 --- a/plugins/woocommerce/src/Internal/Features/FeaturesController.php +++ b/plugins/woocommerce/src/Internal/Features/FeaturesController.php @@ -9,6 +9,7 @@ use Automattic\Jetpack\Constants; use Automattic\WooCommerce\Internal\Admin\Analytics; use Automattic\WooCommerce\Admin\Features\Navigation\Init; use Automattic\WooCommerce\Admin\Features\NewProductManagementExperience; +use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController; use Automattic\WooCommerce\Internal\DataStores\Orders\DataSynchronizer; use Automattic\WooCommerce\Internal\Traits\AccessiblePrivateMethods; use Automattic\WooCommerce\Proxies\LegacyProxy; @@ -472,7 +473,15 @@ class FeaturesController { $matches = array(); $success = preg_match( '/^woocommerce_feature_([a-zA-Z0-9_]+)_enabled$/', $option, $matches ); - if ( ! $success && Analytics::TOGGLE_OPTION_NAME !== $option && Init::TOGGLE_OPTION_NAME !== $option && NewProductManagementExperience::TOGGLE_OPTION_NAME !== $option ) { + $known_features = array( + Analytics::TOGGLE_OPTION_NAME, + Init::TOGGLE_OPTION_NAME, + NewProductManagementExperience::TOGGLE_OPTION_NAME, + DataSynchronizer::ORDERS_DATA_SYNC_ENABLED_OPTION, + CustomOrdersTableController::CUSTOM_ORDERS_TABLE_USAGE_ENABLED_OPTION, + ); + + if ( ! $success && ! in_array( $option, $known_features, true ) ) { return; } @@ -484,6 +493,8 @@ class FeaturesController { $feature_id = 'analytics'; } elseif ( Init::TOGGLE_OPTION_NAME === $option ) { $feature_id = 'new_navigation'; + } elseif ( in_array( $option, $known_features, true ) ) { + $feature_id = $option; } else { $feature_id = $matches[1]; }