From 679339ec9547394c5511da498845b37f9b820724 Mon Sep 17 00:00:00 2001 From: Moon Date: Mon, 20 Mar 2023 11:30:48 -0700 Subject: [PATCH] Refresh data source poller transients on wc_admin_daily (#37027) * Refresh data source poller transients on wc_admin_daily * Add changelog * Conditionally refresh data source pollers * Fix style * Check woocommerce-pyaments -- woocommerce-payments can override payments task * Add marketing task check for RemoteFreeExtensionsDataSourcePoller --- ...7025-refresh-datasources-on-wc_admin_daily | 4 ++++ .../woocommerce/src/Internal/Admin/Events.php | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 plugins/woocommerce/changelog/update-37025-refresh-datasources-on-wc_admin_daily diff --git a/plugins/woocommerce/changelog/update-37025-refresh-datasources-on-wc_admin_daily b/plugins/woocommerce/changelog/update-37025-refresh-datasources-on-wc_admin_daily new file mode 100644 index 00000000000..6eecdbe0bbe --- /dev/null +++ b/plugins/woocommerce/changelog/update-37025-refresh-datasources-on-wc_admin_daily @@ -0,0 +1,4 @@ +Significance: minor +Type: update + +Refresh data source poller transients on wc_admin_daily diff --git a/plugins/woocommerce/src/Internal/Admin/Events.php b/plugins/woocommerce/src/Internal/Admin/Events.php index edb5e13a7b7..e745fe7c86d 100644 --- a/plugins/woocommerce/src/Internal/Admin/Events.php +++ b/plugins/woocommerce/src/Internal/Admin/Events.php @@ -44,6 +44,8 @@ use Automattic\WooCommerce\Internal\Admin\Notes\WooCommerceSubscriptions; use Automattic\WooCommerce\Internal\Admin\Notes\WooSubscriptionsNotes; use Automattic\WooCommerce\Internal\Admin\Schedulers\MailchimpScheduler; use Automattic\WooCommerce\Admin\Notes\Note; +use Automattic\WooCommerce\Admin\Features\PaymentGatewaySuggestions\PaymentGatewaySuggestionsDataSourcePoller; +use Automattic\WooCommerce\Internal\Admin\RemoteFreeExtensions\RemoteFreeExtensionsDataSourcePoller; /** * Events Class. @@ -143,6 +145,7 @@ class Events { $this->possibly_add_notes(); $this->possibly_delete_notes(); $this->possibly_update_notes(); + $this->possibly_refresh_data_source_pollers(); if ( $this->is_remote_inbox_notifications_enabled() ) { DataSourcePoller::get_instance()->read_specs_from_data_sources(); @@ -250,4 +253,21 @@ class Events { // All checks have passed. return true; } + + /** + * Refresh transient for the following DataSourcePollers on wc_admin_daily cron job. + * - PaymentGatewaySuggestionsDataSourcePoller + * - RemoteFreeExtensionsDataSourcePoller + */ + protected function possibly_refresh_data_source_pollers() { + $completed_tasks = get_option( 'woocommerce_task_list_tracked_completed_tasks' ); + + if ( ! in_array( 'payments', $completed_tasks, true ) && ! in_array( 'woocommerce-payments', $completed_tasks, true ) ) { + PaymentGatewaySuggestionsDataSourcePoller::get_instance()->read_specs_from_data_sources(); + } + + if ( ! in_array( 'store_details', $completed_tasks, true ) && ! in_array( 'marketing', $completed_tasks, true ) ) { + RemoteFreeExtensionsDataSourcePoller::get_instance()->read_specs_from_data_sources(); + } + } }