Commit 9a10fdffed for woocommerce
commit 9a10fdffed65cd4e0fd6520a56c5623d8ad382f5
Author: Chi-Hsuan Huang <chihsuan.tw@gmail.com>
Date: Fri Nov 28 18:03:37 2025 +0900
Add analytics-scheduled-import feature flag (#62149)
* Add analytics-scheduled-import feature flag
- Added conditional checks in OrdersScheduler to handle immediate import options based on the new 'analytics-scheduled-import' feature flag.
- Updated core.json and development.json to configure the feature flag for different environments.
- Improved maintainability by ensuring that immediate import logic only executes when the feature is enabled.
* Enhance documentation for immediate import check in OrdersScheduler
- Updated the docblock for the immediate import check method to clarify its behavior when the "analytics-scheduled-import" feature is enabled or disabled.
- Added setup and teardown methods in OrdersSchedulerTest to manage the state of the feature flag during tests, ensuring accurate test conditions.
* Add changefile(s) from automation for the following project(s): woocommerce, woocommerce/client/admin
* Add changefile(s) from automation for the following project(s): woocommerce, woocommerce/client/admin
* Fix lint
* Add changefile(s) from automation for the following project(s): woocommerce, woocommerce/client/admin
* Delete plugins/woocommerce/changelog/62148-wooa7s-797-add-analytics-scheduled-updates-feature-flag
---------
Co-authored-by: github-actions <github-actions@github.com>
diff --git a/plugins/woocommerce/changelog/62149-wooa7s-797-add-analytics-scheduled-updates-feature-flag b/plugins/woocommerce/changelog/62149-wooa7s-797-add-analytics-scheduled-updates-feature-flag
new file mode 100644
index 0000000000..01808f6118
--- /dev/null
+++ b/plugins/woocommerce/changelog/62149-wooa7s-797-add-analytics-scheduled-updates-feature-flag
@@ -0,0 +1,4 @@
+Significance: patch
+Type: add
+
+Add analytics-scheduled-import feature flag to control scheduled analytics imports feature
\ No newline at end of file
diff --git a/plugins/woocommerce/client/admin/config/core.json b/plugins/woocommerce/client/admin/config/core.json
index 5cd9d0e3d5..cb00d67250 100644
--- a/plugins/woocommerce/client/admin/config/core.json
+++ b/plugins/woocommerce/client/admin/config/core.json
@@ -2,6 +2,7 @@
"features": {
"activity-panels": true,
"analytics": true,
+ "analytics-scheduled-import": false,
"product-block-editor": true,
"product-data-views": false,
"experimental-blocks": false,
diff --git a/plugins/woocommerce/client/admin/config/development.json b/plugins/woocommerce/client/admin/config/development.json
index 053148d4cb..b14ae52bab 100644
--- a/plugins/woocommerce/client/admin/config/development.json
+++ b/plugins/woocommerce/client/admin/config/development.json
@@ -2,6 +2,7 @@
"features": {
"activity-panels": true,
"analytics": true,
+ "analytics-scheduled-import": true,
"product-block-editor": true,
"product-data-views": false,
"experimental-blocks": true,
diff --git a/plugins/woocommerce/src/Internal/Admin/Schedulers/OrdersScheduler.php b/plugins/woocommerce/src/Internal/Admin/Schedulers/OrdersScheduler.php
index d4a75fe3e3..89aa0360ba 100644
--- a/plugins/woocommerce/src/Internal/Admin/Schedulers/OrdersScheduler.php
+++ b/plugins/woocommerce/src/Internal/Admin/Schedulers/OrdersScheduler.php
@@ -16,6 +16,7 @@ use Automattic\WooCommerce\Admin\API\Reports\Products\DataStore as ProductsDataS
use Automattic\WooCommerce\Admin\API\Reports\Taxes\DataStore as TaxesDataStore;
use Automattic\WooCommerce\Internal\DataStores\Orders\OrdersTableDataStore;
use Automattic\WooCommerce\Utilities\OrderUtil;
+use Automattic\WooCommerce\Admin\Features\Features;
/**
* OrdersScheduler Class.
@@ -86,10 +87,13 @@ class OrdersScheduler extends ImportScheduler {
// Schedule recurring batch processor.
add_action( 'action_scheduler_ensure_recurring_actions', array( __CLASS__, 'schedule_recurring_batch_processor' ) );
}
- // Watch for changes to the immediate import option.
- add_action( 'add_option_' . self::IMMEDIATE_IMPORT_OPTION, array( __CLASS__, 'handle_immediate_import_option_added' ), 10, 2 );
- add_action( 'update_option_' . self::IMMEDIATE_IMPORT_OPTION, array( __CLASS__, 'handle_immediate_import_option_change' ), 10, 2 );
- add_action( 'delete_option', array( __CLASS__, 'handle_immediate_import_option_before_delete' ), 10, 1 );
+
+ if ( Features::is_enabled( 'analytics-scheduled-import' ) ) {
+ // Watch for changes to the immediate import option.
+ add_action( 'add_option_' . self::IMMEDIATE_IMPORT_OPTION, array( __CLASS__, 'handle_immediate_import_option_added' ), 10, 2 );
+ add_action( 'update_option_' . self::IMMEDIATE_IMPORT_OPTION, array( __CLASS__, 'handle_immediate_import_option_change' ), 10, 2 );
+ add_action( 'delete_option', array( __CLASS__, 'handle_immediate_import_option_before_delete' ), 10, 1 );
+ }
OrdersStatsDataStore::init();
CouponsDataStore::init();
@@ -679,12 +683,20 @@ AND status NOT IN ( 'wc-auto-draft', 'trash', 'auto-draft' )
}
/**
- * Check if immediate import is enabled.
+ * Check whether immediate import is enabled.
+ *
+ * When the "analytics-scheduled-import" feature is disabled, only immediate
+ * import is supported (returns true). When enabled, checks the option value.
*
* @internal
* @return bool
*/
private static function is_immediate_import_enabled(): bool {
+ if ( ! Features::is_enabled( 'analytics-scheduled-import' ) ) {
+ // If the feature is disabled, only immediate import is supported.
+ return true;
+ }
+
return 'no' !== get_option( self::IMMEDIATE_IMPORT_OPTION, self::IMMEDIATE_IMPORT_OPTION_DEFAULT_VALUE );
}
}
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/Schedulers/OrdersSchedulerTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/Schedulers/OrdersSchedulerTest.php
index ec66777d33..60b17a0b12 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/Schedulers/OrdersSchedulerTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/Schedulers/OrdersSchedulerTest.php
@@ -5,6 +5,7 @@ namespace Automattic\WooCommerce\Tests\Internal\Admin\Schedulers;
use Automattic\WooCommerce\Internal\Admin\Schedulers\OrdersScheduler;
use WC_Unit_Test_Case;
+use Automattic\WooCommerce\Admin\Features\Features;
/**
* OrdersScheduler Test.
@@ -13,6 +14,16 @@ use WC_Unit_Test_Case;
*/
class OrdersSchedulerTest extends WC_Unit_Test_Case {
+ /**
+ * Set up the test environment.
+ */
+ public function setUp(): void {
+ parent::setUp();
+
+ // Enable the analytics-scheduled-import feature.
+ Features::enable( 'analytics-scheduled-import' );
+ }
+
/**
* Tear down the test environment.
*/
@@ -26,6 +37,8 @@ class OrdersSchedulerTest extends WC_Unit_Test_Case {
// Clean up any scheduled actions.
$this->clear_scheduled_batch_processor();
+
+ Features::disable( 'analytics-scheduled-import' );
}
/**