From 54856657270081a2d17e1c299e118907b08c2b52 Mon Sep 17 00:00:00 2001 From: Ilyas Foo Date: Tue, 19 Mar 2024 22:15:05 +0800 Subject: [PATCH] Refactor remote specs structure and naming (#45547) * Deprecate DataSourcePoller * Deprecate and move all rule processors and transformers * Lint * More deprecation * Remove extra line * Update deprecated class to not produce too many messages by limiting to unique messages * Changelog * Update all dependency uses, move TransformerService and TransformerInterface to Transformers package * More dependency update * Changelog * Fix wrong file reference * Lint markdown * Lint markdown * Add unsaved file * Delete unused file and more lint * More lint * Ugh ignore faulty lint rule * Rename variables for lint --- ...-wca-test-helper-remote-spec-validator.php | 2 +- ...refactor-remote-specs-structure-and-naming | 4 + ...refactor-remote-specs-structure-and-naming | 4 + .../includes/admin/class-wc-admin-addons.php | 3 +- .../src/Admin/DataSourcePoller.php | 246 ++------- .../src/Admin/DeprecatedClassFacade.php | 24 +- ...rketingRecommendationsDataSourcePoller.php | 2 +- .../EvaluateSuggestion.php | 2 +- ...mentGatewaySuggestionsDataSourcePoller.php | 2 +- ...pingPartnerSuggestionsDataSourcePoller.php | 2 +- .../BaseLocationCountryRuleProcessor.php | 57 +-- .../BaseLocationStateRuleProcessor.php | 44 +- .../ComparisonOperation.php | 73 +-- .../EvaluateAndGetStatus.php | 54 +- .../EvaluationLogger.php | 81 +-- .../FailRuleProcessor.php | 27 +- .../GetRuleProcessor.php | 66 +-- .../IsEcommerceRuleProcessor.php | 36 +- .../IsWooExpressRuleProcessor.php | 57 +-- .../NotRuleProcessor.php | 55 +- .../NoteStatusRuleProcessor.php | 48 +- .../OnboardingProfileRuleProcessor.php | 54 +- .../OptionRuleProcessor.php | 94 +--- .../OrRuleProcessor.php | 62 +-- .../OrderCountRuleProcessor.php | 60 +-- .../OrdersProvider.php | 27 +- .../PassRuleProcessor.php | 27 +- .../PluginVersionRuleProcessor.php | 73 +-- .../PluginsActivatedRuleProcessor.php | 70 +-- .../ProductCountRuleProcessor.php | 67 +-- .../PublishAfterTimeRuleProcessor.php | 56 +- .../PublishBeforeTimeRuleProcessor.php | 56 +- .../Admin/RemoteInboxNotifications/README.md | 478 +---------------- ...oteInboxNotificationsDataSourcePoller.php} | 5 +- .../RemoteInboxNotificationsEngine.php | 5 +- .../RuleEvaluator.php | 81 +-- .../RemoteInboxNotifications/SpecRunner.php | 2 + .../StoredStateRuleProcessor.php | 47 +- .../StoredStateSetupForProducts.php | 120 +---- .../TotalPaymentsVolumeProcessor.php | 82 +-- .../TransformerInterface.php | 4 +- .../TransformerService.php | 73 +-- .../Transformers/ArrayColumn.php | 48 +- .../Transformers/ArrayFlatten.php | 41 +- .../Transformers/ArrayKeys.php | 33 +- .../Transformers/ArraySearch.php | 45 +- .../Transformers/ArrayValues.php | 33 +- .../Transformers/Count.php | 33 +- .../Transformers/DotNotation.php | 71 +-- .../Transformers/PrepareUrl.php | 47 +- .../WCAdminActiveForProvider.php | 23 +- .../WCAdminActiveForRuleProcessor.php | 68 +-- .../WooCommerceAdminUpdatedRuleProcessor.php | 27 +- .../Admin/RemoteSpecs/DataSourcePoller.php | 288 +++++++++++ .../BaseLocationCountryRuleProcessor.php | 70 +++ .../BaseLocationStateRuleProcessor.php | 55 ++ .../RuleProcessors/ComparisonOperation.php | 76 +++ .../RuleProcessors/EvaluateAndGetStatus.php | 59 +++ .../RuleProcessors/EvaluationLogger.php | 90 ++++ .../RuleProcessors/FailRuleProcessor.php | 36 ++ .../RuleProcessors/GetRuleProcessor.php | 69 +++ .../IsEcommerceRuleProcessor.php | 49 ++ .../IsWooExpressRuleProcessor.php | 69 +++ .../RuleProcessors/NotRuleProcessor.php | 64 +++ .../NoteStatusRuleProcessor.php | 61 +++ .../OnboardingProfileRuleProcessor.php | 65 +++ .../RuleProcessors/OptionRuleProcessor.php | 105 ++++ .../RuleProcessors/OrRuleProcessor.php | 73 +++ .../OrderCountRuleProcessor.php | 69 +++ .../RuleProcessors/OrdersProvider.php | 36 ++ .../RuleProcessors/PassRuleProcessor.php | 37 ++ .../PluginVersionRuleProcessor.php | 86 ++++ .../PluginsActivatedRuleProcessor.php | 81 +++ .../ProductCountRuleProcessor.php | 78 +++ .../PublishAfterTimeRuleProcessor.php | 67 +++ .../PublishBeforeTimeRuleProcessor.php | 67 +++ .../RemoteSpecs/RuleProcessors/README.md | 479 ++++++++++++++++++ .../RuleProcessors/RuleEvaluator.php | 92 ++++ .../RuleProcessors/RuleProcessorInterface.php | 32 ++ .../StoredStateRuleProcessor.php | 58 +++ .../StoredStateSetupForProducts.php | 132 +++++ .../TotalPaymentsVolumeProcessor.php | 93 ++++ .../Transformers/ArrayColumn.php | 56 ++ .../Transformers/ArrayFlatten.php | 49 ++ .../RuleProcessors/Transformers/ArrayKeys.php | 41 ++ .../Transformers/ArraySearch.php | 53 ++ .../Transformers/ArrayValues.php | 41 ++ .../RuleProcessors/Transformers/Count.php | 41 ++ .../Transformers/DotNotation.php | 79 +++ .../Transformers/PrepareUrl.php | 55 ++ .../RuleProcessors/Transformers/README.md | 404 +++++++++++++++ .../Transformers/TransformerInterface.php | 34 ++ .../Transformers/TransformerService.php | 83 +++ .../WCAdminActiveForProvider.php | 24 + .../WCAdminActiveForRuleProcessor.php | 79 +++ .../WooCommerceAdminUpdatedRuleProcessor.php | 38 ++ .../woocommerce/src/Internal/Admin/Events.php | 4 +- .../EvaluateExtension.php | 2 +- .../RemoteFreeExtensionsDataSourcePoller.php | 3 +- .../WCPayPromotionDataSourcePoller.php | 4 +- .../data-source-poller.php | 2 +- .../payment-gateway-suggestions.php | 3 +- .../Transformers/array-column.php | 2 +- .../Transformers/array-flatten.php | 2 +- .../Transformers/array-keys.php | 2 +- .../Transformers/array-search.php | 2 +- .../Transformers/array-values.php | 2 +- .../Transformers/count.php | 2 +- .../Transformers/dot-notation.php | 2 +- .../Transformers/prepare-url.php | 2 +- .../base-location-country-rule-processor.php | 2 +- .../base-location-state-rule-processor.php | 2 +- .../comparison-operation.php | 2 +- .../evaluate-and-get-status.php | 2 +- .../get-rule-processor.php | 4 +- .../is-woo-express-rule-processor.php | 2 +- .../mock-get-rule-processor.php | 4 +- .../not-rule-processor.php | 4 +- .../onboarding-profile-rule-processor.php | 2 +- .../option-rule-processor.php | 2 +- .../or-rule-processor.php | 4 +- .../plugin-version-rule-processor.php | 2 +- .../plugins-activated-rule-processor.php | 2 +- .../product-count-rule-processor.php | 2 +- .../publish-after-time-rule-processor.php | 2 +- .../publish-before-time-rule-processor.php | 2 +- .../remote-inbox-notifications-engine.php | 8 +- .../stored-state-rule-processor.php | 3 +- .../total-payments-volume-processor.php | 2 +- .../transformer-service.php | 4 +- .../wcadmin-active-for-rule-processor.php | 2 +- .../MarketingRecommendations/InitTest.php | 2 +- .../Admin/RemoteFreeExtensions/InitTest.php | 2 +- .../ShippingPartnerSuggestionsTest.php | 2 +- .../Admin/WCPayPromotion/InitTest.php | 2 +- 135 files changed, 4249 insertions(+), 2466 deletions(-) create mode 100644 plugins/woocommerce-beta-tester/changelog/dev-44451-refactor-remote-specs-structure-and-naming create mode 100644 plugins/woocommerce/changelog/dev-44451-refactor-remote-specs-structure-and-naming rename plugins/woocommerce/src/Admin/RemoteInboxNotifications/{DataSourcePoller.php => RemoteInboxNotificationsDataSourcePoller.php} (96%) create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/DataSourcePoller.php create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/BaseLocationCountryRuleProcessor.php create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/BaseLocationStateRuleProcessor.php create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/ComparisonOperation.php create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/EvaluateAndGetStatus.php create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/EvaluationLogger.php create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/FailRuleProcessor.php create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/GetRuleProcessor.php create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/IsEcommerceRuleProcessor.php create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/IsWooExpressRuleProcessor.php create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/NotRuleProcessor.php create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/NoteStatusRuleProcessor.php create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/OnboardingProfileRuleProcessor.php create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/OptionRuleProcessor.php create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/OrRuleProcessor.php create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/OrderCountRuleProcessor.php create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/OrdersProvider.php create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/PassRuleProcessor.php create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/PluginVersionRuleProcessor.php create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/PluginsActivatedRuleProcessor.php create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/ProductCountRuleProcessor.php create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/PublishAfterTimeRuleProcessor.php create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/PublishBeforeTimeRuleProcessor.php create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/README.md create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/RuleEvaluator.php create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/RuleProcessorInterface.php create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/StoredStateRuleProcessor.php create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/StoredStateSetupForProducts.php create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/TotalPaymentsVolumeProcessor.php create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/Transformers/ArrayColumn.php create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/Transformers/ArrayFlatten.php create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/Transformers/ArrayKeys.php create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/Transformers/ArraySearch.php create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/Transformers/ArrayValues.php create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/Transformers/Count.php create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/Transformers/DotNotation.php create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/Transformers/PrepareUrl.php create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/Transformers/README.md create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/Transformers/TransformerInterface.php create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/Transformers/TransformerService.php create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/WCAdminActiveForProvider.php create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/WCAdminActiveForRuleProcessor.php create mode 100644 plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/WooCommerceAdminUpdatedRuleProcessor.php diff --git a/plugins/woocommerce-beta-tester/api/remote-spec-validator/class-wca-test-helper-remote-spec-validator.php b/plugins/woocommerce-beta-tester/api/remote-spec-validator/class-wca-test-helper-remote-spec-validator.php index d0b00a4c50fd..0c363cf10c94 100644 --- a/plugins/woocommerce-beta-tester/api/remote-spec-validator/class-wca-test-helper-remote-spec-validator.php +++ b/plugins/woocommerce-beta-tester/api/remote-spec-validator/class-wca-test-helper-remote-spec-validator.php @@ -2,7 +2,7 @@ defined( 'ABSPATH' ) || exit; -use Automattic\WooCommerce\Admin\RemoteInboxNotifications\RuleEvaluator; +use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\RuleEvaluator; register_woocommerce_admin_test_helper_rest_route( '/remote-spec-validator/validate', diff --git a/plugins/woocommerce-beta-tester/changelog/dev-44451-refactor-remote-specs-structure-and-naming b/plugins/woocommerce-beta-tester/changelog/dev-44451-refactor-remote-specs-structure-and-naming new file mode 100644 index 000000000000..0f53aaf7ad1f --- /dev/null +++ b/plugins/woocommerce-beta-tester/changelog/dev-44451-refactor-remote-specs-structure-and-naming @@ -0,0 +1,4 @@ +Significance: patch +Type: dev + +Update import path diff --git a/plugins/woocommerce/changelog/dev-44451-refactor-remote-specs-structure-and-naming b/plugins/woocommerce/changelog/dev-44451-refactor-remote-specs-structure-and-naming new file mode 100644 index 000000000000..9138a9b369e7 --- /dev/null +++ b/plugins/woocommerce/changelog/dev-44451-refactor-remote-specs-structure-and-naming @@ -0,0 +1,4 @@ +Significance: minor +Type: dev + +Refactor remote specs structure and naming diff --git a/plugins/woocommerce/includes/admin/class-wc-admin-addons.php b/plugins/woocommerce/includes/admin/class-wc-admin-addons.php index 075c97229486..7c092002e10d 100644 --- a/plugins/woocommerce/includes/admin/class-wc-admin-addons.php +++ b/plugins/woocommerce/includes/admin/class-wc-admin-addons.php @@ -8,6 +8,7 @@ use Automattic\Jetpack\Constants; use Automattic\WooCommerce\Admin\RemoteInboxNotifications as PromotionRuleEngine; +use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\RuleEvaluator; if ( ! defined( 'ABSPATH' ) ) { exit; @@ -1075,7 +1076,7 @@ public static function output() { // Check for existence of promotions and evaluate out if we should show them. if ( ! empty( $promotions ) ) { foreach ( $promotions as $promo_id => $promotion ) { - $evaluator = new PromotionRuleEngine\RuleEvaluator(); + $evaluator = new RuleEvaluator(); $passed = $evaluator->evaluate( $promotion->rules ); if ( ! $passed ) { unset( $promotions[ $promo_id ] ); diff --git a/plugins/woocommerce/src/Admin/DataSourcePoller.php b/plugins/woocommerce/src/Admin/DataSourcePoller.php index f2688d56ba71..707c4c7792df 100644 --- a/plugins/woocommerce/src/Admin/DataSourcePoller.php +++ b/plugins/woocommerce/src/Admin/DataSourcePoller.php @@ -2,55 +2,29 @@ namespace Automattic\WooCommerce\Admin; +use Automattic\WooCommerce\Admin\RemoteSpecs\DataSourcePoller as RemoteSpecsDataSourcePoller; + /** * Specs data source poller class. * This handles polling specs from JSON endpoints, and * stores the specs in to the database as an option. + * + * @deprecated since 8.8.0 */ -abstract class DataSourcePoller { - - /** - * Get class instance. - */ - abstract public static function get_instance(); - - /** - * Name of data sources filter. - */ - const FILTER_NAME = 'data_source_poller_data_sources'; - - /** - * Name of data source specs filter. - */ - const FILTER_NAME_SPECS = 'data_source_poller_specs'; - - /** - * Id of DataSourcePoller. - * - * @var string - */ - protected $id = array(); - +abstract class DataSourcePoller extends RemoteSpecsDataSourcePoller { /** - * Default data sources array. - * - * @var array - */ - protected $data_sources = array(); - - /** - * Default args. - * - * @var array + * Log a deprecation to the error log. */ - protected $args = array(); - - /** - * The logger instance. - * - * @var WC_Logger|null - */ - protected static $logger = null; + private static function log_deprecation() { + error_log( // phpcs:ignore + sprintf( + '%1$s is deprecated since version %2$s! Use %3$s instead.', + self::class, + '8.8.0', + 'Automattic\WooCommerce\Admin\RemoteSpecs\DataSourcePoller' + ) + ); + } /** * Constructor. @@ -60,98 +34,41 @@ abstract public static function get_instance(); * @param array $args Options for DataSourcePoller. */ public function __construct( $id, $data_sources = array(), $args = array() ) { - $this->data_sources = $data_sources; - $this->id = $id; - - $arg_defaults = array( - 'spec_key' => 'id', - 'transient_name' => 'woocommerce_admin_' . $id . '_specs', - 'transient_expiry' => 7 * DAY_IN_SECONDS, - ); - $this->args = wp_parse_args( $args, $arg_defaults ); - } - - /** - * Get the logger instance. - * - * @return WC_Logger - */ - protected static function get_logger() { - if ( is_null( self::$logger ) ) { - self::$logger = wc_get_logger(); - } - - return self::$logger; - } - - /** - * Returns the key identifier of spec, this can easily be overwritten. Defaults to id. - * - * @param mixed $spec a JSON parsed spec coming from the JSON feed. - * @return string|boolean - */ - protected function get_spec_key( $spec ) { - $key = $this->args['spec_key']; - if ( isset( $spec->$key ) ) { - return $spec->$key; - } - return false; + self::log_deprecation(); + parent::__construct( $id, $data_sources, $args ); } /** * Reads the data sources for specs and persists those specs. * + * @deprecated 8.8.0 * @return array list of specs. */ public function get_specs_from_data_sources() { - $locale = get_user_locale(); - $specs_group = get_transient( $this->args['transient_name'] ) ?? array(); - $specs = isset( $specs_group[ $locale ] ) ? $specs_group[ $locale ] : array(); - - if ( ! is_array( $specs ) || empty( $specs ) ) { - $this->read_specs_from_data_sources(); - $specs_group = get_transient( $this->args['transient_name'] ); - $specs = isset( $specs_group[ $locale ] ) ? $specs_group[ $locale ] : array(); - } - $specs = apply_filters( self::FILTER_NAME_SPECS, $specs, $this->id ); - return $specs !== false ? $specs : array(); + self::log_deprecation(); + return parent::get_specs_from_data_sources(); } /** * Reads the data sources for specs and persists those specs. * + * @deprecated 8.8.0 * @return bool Whether any specs were read. */ public function read_specs_from_data_sources() { - $specs = array(); - $data_sources = apply_filters( self::FILTER_NAME, $this->data_sources, $this->id ); - - // Note that this merges the specs from the data sources based on the - // id - last one wins. - foreach ( $data_sources as $url ) { - $specs_from_data_source = self::read_data_source( $url ); - $this->merge_specs( $specs_from_data_source, $specs, $url ); - } - - $specs_group = get_transient( $this->args['transient_name'] ); - $specs_group = is_array( $specs_group ) ? $specs_group : array(); - $locale = get_user_locale(); - $specs_group[ $locale ] = $specs; - // Persist the specs as a transient. - $this->set_specs_transient( - $specs_group, - $this->args['transient_expiry'] - ); - return count( $specs ) !== 0; + self::log_deprecation(); + return parent::read_specs_from_data_sources(); } /** * Delete the specs transient. * + * @deprecated 8.8.0 * @return bool success of failure of transient deletion. */ public function delete_specs_transient() { - return delete_transient( $this->args['transient_name'] ); + self::log_deprecation(); + return parent::delete_specs_transient(); } /** @@ -159,112 +76,11 @@ public function delete_specs_transient() { * * @param array $specs The specs to set in the transient. * @param int $expiration The expiration time for the transient. - */ - public function set_specs_transient( $specs, $expiration = 0 ) { - set_transient( - $this->args['transient_name'], - $specs, - $expiration, - ); - } - - /** - * Read a single data source and return the read specs - * - * @param string $url The URL to read the specs from. - * - * @return array The specs that have been read from the data source. - */ - protected static function read_data_source( $url ) { - $logger_context = array( 'source' => $url ); - $logger = self::get_logger(); - $response = wp_remote_get( - add_query_arg( - 'locale', - get_user_locale(), - $url - ), - array( - 'user-agent' => 'WooCommerce/' . WC_VERSION . '; ' . home_url( '/' ), - ) - ); - - if ( is_wp_error( $response ) || ! isset( $response['body'] ) ) { - $logger->error( - 'Error getting data feed', - $logger_context - ); - // phpcs:ignore - $logger->error( print_r( $response, true ), $logger_context ); - - return array(); - } - - $body = $response['body']; - $specs = json_decode( $body ); - - if ( $specs === null ) { - $logger->error( - 'Empty response in data feed', - $logger_context - ); - - return array(); - } - - if ( ! is_array( $specs ) ) { - $logger->error( - 'Data feed is not an array', - $logger_context - ); - - return array(); - } - - return $specs; - } - - /** - * Merge the specs. * - * @param Array $specs_to_merge_in The specs to merge in to $specs. - * @param Array $specs The list of specs being merged into. - * @param string $url The url of the feed being merged in (for error reporting). + * @deprecated 8.8.0 */ - protected function merge_specs( $specs_to_merge_in, &$specs, $url ) { - foreach ( $specs_to_merge_in as $spec ) { - if ( ! $this->validate_spec( $spec, $url ) ) { - continue; - } - - $id = $this->get_spec_key( $spec ); - $specs[ $id ] = $spec; - } - } - - /** - * Validate the spec. - * - * @param object $spec The spec to validate. - * @param string $url The url of the feed that provided the spec. - * - * @return bool The result of the validation. - */ - protected function validate_spec( $spec, $url ) { - $logger = self::get_logger(); - $logger_context = array( 'source' => $url ); - - if ( ! $this->get_spec_key( $spec ) ) { - $logger->error( - 'Spec is invalid because the id is missing in feed', - $logger_context - ); - // phpcs:ignore - $logger->error( print_r( $spec, true ), $logger_context ); - - return false; - } - - return true; + public function set_specs_transient( $specs, $expiration = 0 ) { + self::log_deprecation(); + return parent::set_specs_transient( $specs, $expiration ); } } diff --git a/plugins/woocommerce/src/Admin/DeprecatedClassFacade.php b/plugins/woocommerce/src/Admin/DeprecatedClassFacade.php index 9133eb560dfd..527da3b94a02 100644 --- a/plugins/woocommerce/src/Admin/DeprecatedClassFacade.php +++ b/plugins/woocommerce/src/Admin/DeprecatedClassFacade.php @@ -47,6 +47,12 @@ class DeprecatedClassFacade { */ protected static $deprecated_in_version = ''; + /** + * Static array of logged messages. + * + * @var array + */ + private static $logged_messages = array(); /** * Constructor. @@ -61,14 +67,18 @@ public function __construct() { * @param string $function The name of the deprecated function being called. */ private static function log_deprecation( $function ) { - error_log( // phpcs:ignore - sprintf( - '%1$s is deprecated since version %2$s! Use %3$s instead.', - static::class . '::' . $function, - static::$deprecated_in_version, - static::$facade_over_classname . '::' . $function - ) + $message = sprintf( + '%1$s is deprecated since version %2$s! Use %3$s instead.', + static::class . '::' . $function, + static::$deprecated_in_version, + static::$facade_over_classname . '::' . $function ); + + // Only log when the message has not been logged before. + if ( ! in_array( $message, self::$logged_messages, true ) ) { + error_log( $message ); // phpcs:ignore + self::$logged_messages[] = $message; + } } /** diff --git a/plugins/woocommerce/src/Admin/Features/MarketingRecommendations/MarketingRecommendationsDataSourcePoller.php b/plugins/woocommerce/src/Admin/Features/MarketingRecommendations/MarketingRecommendationsDataSourcePoller.php index 66e498260668..35d060135a06 100644 --- a/plugins/woocommerce/src/Admin/Features/MarketingRecommendations/MarketingRecommendationsDataSourcePoller.php +++ b/plugins/woocommerce/src/Admin/Features/MarketingRecommendations/MarketingRecommendationsDataSourcePoller.php @@ -2,7 +2,7 @@ namespace Automattic\WooCommerce\Admin\Features\MarketingRecommendations; -use Automattic\WooCommerce\Admin\DataSourcePoller; +use Automattic\WooCommerce\Admin\RemoteSpecs\DataSourcePoller; /** * Specs data source poller class for marketing recommendations. diff --git a/plugins/woocommerce/src/Admin/Features/PaymentGatewaySuggestions/EvaluateSuggestion.php b/plugins/woocommerce/src/Admin/Features/PaymentGatewaySuggestions/EvaluateSuggestion.php index 95db859ae4c8..662bbf5631c1 100644 --- a/plugins/woocommerce/src/Admin/Features/PaymentGatewaySuggestions/EvaluateSuggestion.php +++ b/plugins/woocommerce/src/Admin/Features/PaymentGatewaySuggestions/EvaluateSuggestion.php @@ -7,7 +7,7 @@ defined( 'ABSPATH' ) || exit; -use Automattic\WooCommerce\Admin\RemoteInboxNotifications\RuleEvaluator; +use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\RuleEvaluator; /** * Evaluates the spec and returns the evaluated suggestion. diff --git a/plugins/woocommerce/src/Admin/Features/PaymentGatewaySuggestions/PaymentGatewaySuggestionsDataSourcePoller.php b/plugins/woocommerce/src/Admin/Features/PaymentGatewaySuggestions/PaymentGatewaySuggestionsDataSourcePoller.php index 5e3608b635d5..d53ac724afdc 100644 --- a/plugins/woocommerce/src/Admin/Features/PaymentGatewaySuggestions/PaymentGatewaySuggestionsDataSourcePoller.php +++ b/plugins/woocommerce/src/Admin/Features/PaymentGatewaySuggestions/PaymentGatewaySuggestionsDataSourcePoller.php @@ -2,7 +2,7 @@ namespace Automattic\WooCommerce\Admin\Features\PaymentGatewaySuggestions; -use Automattic\WooCommerce\Admin\DataSourcePoller; +use Automattic\WooCommerce\Admin\RemoteSpecs\DataSourcePoller; /** * Specs data source poller class for payment gateway suggestions. diff --git a/plugins/woocommerce/src/Admin/Features/ShippingPartnerSuggestions/ShippingPartnerSuggestionsDataSourcePoller.php b/plugins/woocommerce/src/Admin/Features/ShippingPartnerSuggestions/ShippingPartnerSuggestionsDataSourcePoller.php index c64f76e4868a..b09d388c32bf 100644 --- a/plugins/woocommerce/src/Admin/Features/ShippingPartnerSuggestions/ShippingPartnerSuggestionsDataSourcePoller.php +++ b/plugins/woocommerce/src/Admin/Features/ShippingPartnerSuggestions/ShippingPartnerSuggestionsDataSourcePoller.php @@ -2,7 +2,7 @@ namespace Automattic\WooCommerce\Admin\Features\ShippingPartnerSuggestions; -use Automattic\WooCommerce\Admin\DataSourcePoller; +use Automattic\WooCommerce\Admin\RemoteSpecs\DataSourcePoller; /** * Specs data source poller class for shipping partner suggestions. diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/BaseLocationCountryRuleProcessor.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/BaseLocationCountryRuleProcessor.php index 366c66998858..3854f372b83d 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/BaseLocationCountryRuleProcessor.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/BaseLocationCountryRuleProcessor.php @@ -6,65 +6,28 @@ namespace Automattic\WooCommerce\Admin\RemoteInboxNotifications; -use Automattic\WooCommerce\Internal\Admin\Onboarding\OnboardingProfile; +use Automattic\WooCommerce\Admin\DeprecatedClassFacade; defined( 'ABSPATH' ) || exit; /** * Rule processor that performs a comparison operation against the base * location - country. + * + * @deprecated 8.8.0 */ -class BaseLocationCountryRuleProcessor implements RuleProcessorInterface { +class BaseLocationCountryRuleProcessor extends DeprecatedClassFacade { /** - * Performs a comparison operation against the base location - country. + * The name of the non-deprecated class that this facade covers. * - * @param object $rule The specific rule being processed by this rule processor. - * @param object $stored_state Stored state. - * - * @return bool The result of the operation. + * @var string */ - public function process( $rule, $stored_state ) { - $base_location = wc_get_base_location(); - if ( - ! is_array( $base_location ) || - ! array_key_exists( 'country', $base_location ) || - ! array_key_exists( 'state', $base_location ) - ) { - return false; - } - - $onboarding_profile = get_option( 'woocommerce_onboarding_profile', array() ); - $is_address_default = 'US' === $base_location['country'] && 'CA' === $base_location['state'] && empty( get_option( 'woocommerce_store_address', '' ) ); - $is_store_country_set = isset( $onboarding_profile['is_store_country_set'] ) && $onboarding_profile['is_store_country_set']; - - // Return false if the location is the default country and if onboarding hasn't been finished or the store address not been updated. - if ( $is_address_default && OnboardingProfile::needs_completion() && ! $is_store_country_set ) { - return false; - } - - return ComparisonOperation::compare( - $base_location['country'], - $rule->value, - $rule->operation - ); - } + protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\BaseLocationCountryRuleProcessor'; /** - * Validates the rule. + * The version that this class was deprecated in. * - * @param object $rule The rule to validate. - * - * @return bool Pass/fail. + * @var string */ - public function validate( $rule ) { - if ( ! isset( $rule->value ) ) { - return false; - } - - if ( ! isset( $rule->operation ) ) { - return false; - } - - return true; - } + protected static $deprecated_in_version = '8.8.0'; } diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/BaseLocationStateRuleProcessor.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/BaseLocationStateRuleProcessor.php index 52d7751b029e..fdb25bdfce8b 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/BaseLocationStateRuleProcessor.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/BaseLocationStateRuleProcessor.php @@ -6,50 +6,28 @@ namespace Automattic\WooCommerce\Admin\RemoteInboxNotifications; +use Automattic\WooCommerce\Admin\DeprecatedClassFacade; + defined( 'ABSPATH' ) || exit; /** * Rule processor that performs a comparison operation against the base * location - state. + * + * @deprecated 8.8.0 */ -class BaseLocationStateRuleProcessor implements RuleProcessorInterface { +class BaseLocationStateRuleProcessor extends DeprecatedClassFacade { /** - * Performs a comparison operation against the base location - state. - * - * @param object $rule The specific rule being processed by this rule processor. - * @param object $stored_state Stored state. + * The name of the non-deprecated class that this facade covers. * - * @return bool The result of the operation. + * @var string */ - public function process( $rule, $stored_state ) { - $base_location = wc_get_base_location(); - if ( ! is_array( $base_location ) || ! array_key_exists( 'state', $base_location ) ) { - return false; - } - - return ComparisonOperation::compare( - $base_location['state'], - $rule->value, - $rule->operation - ); - } + protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\BaseLocationStateRuleProcessor'; /** - * Validates the rule. + * The version that this class was deprecated in. * - * @param object $rule The rule to validate. - * - * @return bool Pass/fail. + * @var string */ - public function validate( $rule ) { - if ( ! isset( $rule->value ) ) { - return false; - } - - if ( ! isset( $rule->operation ) ) { - return false; - } - - return true; - } + protected static $deprecated_in_version = '8.8.0'; } diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/ComparisonOperation.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/ComparisonOperation.php index 57f4a2ba1f4d..58531ce25210 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/ComparisonOperation.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/ComparisonOperation.php @@ -7,70 +7,25 @@ defined( 'ABSPATH' ) || exit; +use Automattic\WooCommerce\Admin\DeprecatedClassFacade; + /** * Compare two operands using the specified operation. + * + * @deprecated 8.8.0 */ -class ComparisonOperation { +class ComparisonOperation extends DeprecatedClassFacade { /** - * Compare two operands using the specified operation. + * The name of the non-deprecated class that this facade covers. * - * @param object $left_operand The left hand operand. - * @param object $right_operand The right hand operand -- 'value' from the rule definition. - * @param string $operation The operation used to compare the operands. + * @var string */ - public static function compare( $left_operand, $right_operand, $operation ) { - switch ( $operation ) { - case '=': - return $left_operand === $right_operand; - case '<': - return $left_operand < $right_operand; - case '<=': - return $left_operand <= $right_operand; - case '>': - return $left_operand > $right_operand; - case '>=': - return $left_operand >= $right_operand; - case '!=': - return $left_operand !== $right_operand; - case 'contains': - if ( is_array( $left_operand ) && is_string( $right_operand ) ) { - return in_array( $right_operand, $left_operand, true ); - } - if ( is_string( $right_operand ) && is_string( $left_operand ) ) { - return strpos( $right_operand, $left_operand ) !== false; - } - break; - case '!contains': - if ( is_array( $left_operand ) && is_string( $right_operand ) ) { - return ! in_array( $right_operand, $left_operand, true ); - } - if ( is_string( $right_operand ) && is_string( $left_operand ) ) { - return strpos( $right_operand, $left_operand ) === false; - } - break; - case 'in': - if ( is_array( $right_operand ) && is_string( $left_operand ) ) { - return in_array( $left_operand, $right_operand, true ); - } - if ( is_string( $left_operand ) && is_string( $right_operand ) ) { - return strpos( $left_operand, $right_operand ) !== false; - } - break; - case '!in': - if ( is_array( $right_operand ) && is_string( $left_operand ) ) { - return ! in_array( $left_operand, $right_operand, true ); - } - if ( is_string( $left_operand ) && is_string( $right_operand ) ) { - return strpos( $left_operand, $right_operand ) === false; - } - break; - case 'range': - if ( ! is_array( $right_operand ) || count( $right_operand ) !== 2 ) { - return false; - } - return $left_operand >= $right_operand[0] && $left_operand <= $right_operand[1]; - } + protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\ComparisonOperation'; - return false; - } + /** + * The version that this class was deprecated in. + * + * @var string + */ + protected static $deprecated_in_version = '8.8.0'; } diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/EvaluateAndGetStatus.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/EvaluateAndGetStatus.php index 8872acdc7c04..dced665fab1f 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/EvaluateAndGetStatus.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/EvaluateAndGetStatus.php @@ -7,53 +7,25 @@ defined( 'ABSPATH' ) || exit; -use Automattic\WooCommerce\Admin\Notes\Note; +use Automattic\WooCommerce\Admin\DeprecatedClassFacade; /** * Evaluates the spec and returns a status. + * + * @deprecated 8.8.0 */ -class EvaluateAndGetStatus { +class EvaluateAndGetStatus extends DeprecatedClassFacade { /** - * Evaluates the spec and returns a status. + * The name of the non-deprecated class that this facade covers. * - * @param array $spec The spec to evaluate. - * @param string $current_status The note's current status. - * @param object $stored_state Stored state. - * @param object $rule_evaluator Evaluates rules into true/false. - * - * @return string The evaluated status. + * @var string */ - public static function evaluate( $spec, $current_status, $stored_state, $rule_evaluator ) { - // No rules should leave the note alone. - if ( ! isset( $spec->rules ) ) { - return $current_status; - } - - $evaluated_result = $rule_evaluator->evaluate( - $spec->rules, - $stored_state, - array( - 'slug' => $spec->slug, - 'source' => 'remote-inbox-notifications', - ) - ); - - // Pending notes should be the spec status if the spec passes, - // left alone otherwise. - if ( Note::E_WC_ADMIN_NOTE_PENDING === $current_status ) { - return $evaluated_result - ? $spec->status - : Note::E_WC_ADMIN_NOTE_PENDING; - } - - // When allow_redisplay isn't set, just leave the note alone. - if ( ! isset( $spec->allow_redisplay ) || ! $spec->allow_redisplay ) { - return $current_status; - } + protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\EvaluateAndGetStatus'; - // allow_redisplay is set, unaction the note if eval to true. - return $evaluated_result - ? Note::E_WC_ADMIN_NOTE_UNACTIONED - : $current_status; - } + /** + * The version that this class was deprecated in. + * + * @var string + */ + protected static $deprecated_in_version = '8.8.0'; } diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/EvaluationLogger.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/EvaluationLogger.php index 29f50708e951..a434e04c5654 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/EvaluationLogger.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/EvaluationLogger.php @@ -2,89 +2,26 @@ namespace Automattic\WooCommerce\Admin\RemoteInboxNotifications; +use Automattic\WooCommerce\Admin\DeprecatedClassFacade; /** * Class EvaluationLogger * * @package Automattic\WooCommerce\Admin\RemoteInboxNotifications + * + * @deprecated 8.8.0 */ -class EvaluationLogger { +class EvaluationLogger extends DeprecatedClassFacade { /** - * Slug of the spec. + * The name of the non-deprecated class that this facade covers. * * @var string */ - private $slug; - - /** - * Results of rules in the given spec. - * - * @var array - */ - private $results = array(); - - /** - * Logger class to use. - * - * @var WC_Logger_Interface|null - */ - private $logger; - - /** - * Logger source. - * - * @var string logger source. - */ - private $source = ''; - - /** - * EvaluationLogger constructor. - * - * @param string $slug Slug of a spec that is being evaluated. - * @param null $source Logger source. - * @param \WC_Logger_Interface $logger Logger class to use. - */ - public function __construct( $slug, $source = null, \WC_Logger_Interface $logger = null ) { - $this->slug = $slug; - if ( null === $logger ) { - $logger = wc_get_logger(); - } - - if ( $source ) { - $this->source = $source; - } - - $this->logger = $logger; - } + protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\EvaluationLogger'; /** - * Add evaluation result of a rule. + * The version that this class was deprecated in. * - * @param string $rule_type name of the rule being tested. - * @param boolean $result result of a given rule. - */ - public function add_result( $rule_type, $result ) { - array_push( - $this->results, - array( - 'rule' => $rule_type, - 'result' => $result ? 'passed' : 'failed', - ) - ); - } - - /** - * Log the results. + * @var string */ - public function log() { - if ( false === defined( 'WC_ADMIN_DEBUG_RULE_EVALUATOR' ) || true !== constant( 'WC_ADMIN_DEBUG_RULE_EVALUATOR' ) ) { - return; - } - - foreach ( $this->results as $result ) { - $this->logger->debug( - "[{$this->slug}] {$result['rule']}: {$result['result']}", - array( 'source' => $this->source ) - ); - } - } + protected static $deprecated_in_version = '8.8.0'; } diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/FailRuleProcessor.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/FailRuleProcessor.php index 71c9b9b6f57c..fee92a01081d 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/FailRuleProcessor.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/FailRuleProcessor.php @@ -7,30 +7,25 @@ defined( 'ABSPATH' ) || exit; +use Automattic\WooCommerce\Admin\DeprecatedClassFacade; + /** * Rule processor that fails. + * + * @deprecated 8.8.0 */ -class FailRuleProcessor implements RuleProcessorInterface { +class FailRuleProcessor extends DeprecatedClassFacade { /** - * Fails the rule. - * - * @param object $rule The specific rule being processed by this rule processor. - * @param object $stored_state Stored state. + * The name of the non-deprecated class that this facade covers. * - * @return bool Always false. + * @var string */ - public function process( $rule, $stored_state ) { - return false; - } + protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\FailRuleProcessor'; /** - * Validates the rule. - * - * @param object $rule The rule to validate. + * The version that this class was deprecated in. * - * @return bool Pass/fail. + * @var string */ - public function validate( $rule ) { - return true; - } + protected static $deprecated_in_version = '8.8.0'; } diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/GetRuleProcessor.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/GetRuleProcessor.php index 78d06850bf69..99e52eda4752 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/GetRuleProcessor.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/GetRuleProcessor.php @@ -7,63 +7,25 @@ defined( 'ABSPATH' ) || exit; +use Automattic\WooCommerce\Admin\DeprecatedClassFacade; + /** * Class encapsulating getting the processor for a given rule type. + * + * @deprecated 8.8.0 */ -class GetRuleProcessor { +class GetRuleProcessor extends DeprecatedClassFacade { /** - * Get the processor for the specified rule type. - * - * @param string $rule_type The rule type. + * The name of the non-deprecated class that this facade covers. * - * @return RuleProcessorInterface The matching processor for the specified rule type, or a FailRuleProcessor if no matching processor is found. + * @var string */ - public static function get_processor( $rule_type ) { - switch ( $rule_type ) { - case 'plugins_activated': - return new PluginsActivatedRuleProcessor(); - case 'publish_after_time': - return new PublishAfterTimeRuleProcessor(); - case 'publish_before_time': - return new PublishBeforeTimeRuleProcessor(); - case 'not': - return new NotRuleProcessor(); - case 'or': - return new OrRuleProcessor(); - case 'fail': - return new FailRuleProcessor(); - case 'pass': - return new PassRuleProcessor(); - case 'plugin_version': - return new PluginVersionRuleProcessor(); - case 'stored_state': - return new StoredStateRuleProcessor(); - case 'order_count': - return new OrderCountRuleProcessor(); - case 'wcadmin_active_for': - return new WCAdminActiveForRuleProcessor(); - case 'product_count': - return new ProductCountRuleProcessor(); - case 'onboarding_profile': - return new OnboardingProfileRuleProcessor(); - case 'is_ecommerce': - return new IsEcommerceRuleProcessor(); - case 'is_woo_express': - return new IsWooExpressRuleProcessor(); - case 'base_location_country': - return new BaseLocationCountryRuleProcessor(); - case 'base_location_state': - return new BaseLocationStateRuleProcessor(); - case 'note_status': - return new NoteStatusRuleProcessor(); - case 'option': - return new OptionRuleProcessor(); - case 'wca_updated': - return new WooCommerceAdminUpdatedRuleProcessor(); - case 'total_payments_value': - return new TotalPaymentsVolumeProcessor(); - } + protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\GetRuleProcessor'; - return new FailRuleProcessor(); - } + /** + * The version that this class was deprecated in. + * + * @var string + */ + protected static $deprecated_in_version = '8.8.0'; } diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/IsEcommerceRuleProcessor.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/IsEcommerceRuleProcessor.php index 25e70f7b4c6e..c152f490632e 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/IsEcommerceRuleProcessor.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/IsEcommerceRuleProcessor.php @@ -10,40 +10,26 @@ defined( 'ABSPATH' ) || exit; +use Automattic\WooCommerce\Admin\DeprecatedClassFacade; + /** * Rule processor that passes (or fails) when the site is on the eCommerce * plan. + * + * @deprecated 8.8.0 */ -class IsEcommerceRuleProcessor implements RuleProcessorInterface { +class IsEcommerceRuleProcessor extends DeprecatedClassFacade { /** - * Passes (or fails) based on whether the site is on the eCommerce plan or - * not. - * - * @param object $rule The rule being processed by this rule processor. - * @param object $stored_state Stored state. + * The name of the non-deprecated class that this facade covers. * - * @return bool The result of the operation. + * @var string */ - public function process( $rule, $stored_state ) { - if ( ! function_exists( 'wc_calypso_bridge_is_ecommerce_plan' ) ) { - return false === $rule->value; - } - - return (bool) wc_calypso_bridge_is_ecommerce_plan() === $rule->value; - } + protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\IsEcommerceRuleProcessor'; /** - * Validate the rule. - * - * @param object $rule The rule to validate. + * The version that this class was deprecated in. * - * @return bool Pass/fail. + * @var string */ - public function validate( $rule ) { - if ( ! isset( $rule->value ) ) { - return false; - } - - return true; - } + protected static $deprecated_in_version = '8.8.0'; } diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/IsWooExpressRuleProcessor.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/IsWooExpressRuleProcessor.php index 55418105b46a..a3c2b1f6147e 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/IsWooExpressRuleProcessor.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/IsWooExpressRuleProcessor.php @@ -9,61 +9,26 @@ defined( 'ABSPATH' ) || exit; +use Automattic\WooCommerce\Admin\DeprecatedClassFacade; + /** * Rule processor that passes (or fails) when the site is on a Woo Express plan. * You may optionally pass a plan name to target a specific Woo Express plan. + * + * @deprecated 8.8.0 */ -class IsWooExpressRuleProcessor implements RuleProcessorInterface { +class IsWooExpressRuleProcessor extends DeprecatedClassFacade { /** - * Passes (or fails) based on whether the site is a Woo Express plan. - * - * @param object $rule The rule being processed by this rule processor. - * @param object $stored_state Stored state. + * The name of the non-deprecated class that this facade covers. * - * @return bool The result of the operation. + * @var string */ - public function process( $rule, $stored_state ) { - if ( ! function_exists( 'wc_calypso_bridge_is_woo_express_plan' ) ) { - return false === $rule->value; - } - - // If the plan is undefined, only check if it's a Woo Express plan. - if ( ! isset( $rule->plan ) ) { - return wc_calypso_bridge_is_woo_express_plan() === $rule->value; - } - - // If a plan name is defined, only evaluate the plan if we're on the Woo Express plan. - if ( wc_calypso_bridge_is_woo_express_plan() ) { - $fn = 'wc_calypso_bridge_is_woo_express_' . (string) $rule->plan . '_plan'; - if ( function_exists( $fn ) ) { - return $fn() === $rule->value; - } - - // If an invalid plan name is given, only evaluate the rule if we're targeting all plans other than the specified (invalid) one. - return false === $rule->value; - } - - return false; - } + protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\IsWooExpressRuleProcessor'; /** - * Validate the rule. - * - * @param object $rule The rule to validate. + * The version that this class was deprecated in. * - * @return bool Pass/fail. + * @var string */ - public function validate( $rule ) { - if ( ! isset( $rule->value ) ) { - return false; - } - - if ( isset( $rule->plan ) ) { - if ( ! function_exists( 'wc_calypso_bridge_is_woo_express_plan' ) ) { - return false; - } - } - - return true; - } + protected static $deprecated_in_version = '8.8.0'; } diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/NotRuleProcessor.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/NotRuleProcessor.php index 306db285a7b0..4201c534b6bd 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/NotRuleProcessor.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/NotRuleProcessor.php @@ -7,58 +7,25 @@ defined( 'ABSPATH' ) || exit; +use Automattic\WooCommerce\Admin\DeprecatedClassFacade; + /** * Rule processor that negates the rules in the rule's operand. + * + * @deprecated 8.8.0 */ -class NotRuleProcessor implements RuleProcessorInterface { - - /** - * The rule evaluator to use. - * - * @var RuleEvaluator - */ - protected $rule_evaluator; - - /** - * Constructor. - * - * @param RuleEvaluator $rule_evaluator The rule evaluator to use. - */ - public function __construct( $rule_evaluator = null ) { - $this->rule_evaluator = null === $rule_evaluator - ? new RuleEvaluator() - : $rule_evaluator; - } - +class NotRuleProcessor extends DeprecatedClassFacade { /** - * Evaluates the rules in the operand and negates the result. - * - * @param object $rule The specific rule being processed by this rule processor. - * @param object $stored_state Stored state. + * The name of the non-deprecated class that this facade covers. * - * @return bool The result of the operation. + * @var string */ - public function process( $rule, $stored_state ) { - $evaluated_operand = $this->rule_evaluator->evaluate( - $rule->operand, - $stored_state - ); - - return ! $evaluated_operand; - } + protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\NotRuleProcessor'; /** - * Validates the rule. - * - * @param object $rule The rule to validate. + * The version that this class was deprecated in. * - * @return bool Pass/fail. + * @var string */ - public function validate( $rule ) { - if ( ! isset( $rule->operand ) ) { - return false; - } - - return true; - } + protected static $deprecated_in_version = '8.8.0'; } diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/NoteStatusRuleProcessor.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/NoteStatusRuleProcessor.php index fcfaa56dbdaf..4c804af93f05 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/NoteStatusRuleProcessor.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/NoteStatusRuleProcessor.php @@ -9,53 +9,25 @@ defined( 'ABSPATH' ) || exit; -use Automattic\WooCommerce\Admin\Notes\Notes; +use Automattic\WooCommerce\Admin\DeprecatedClassFacade; /** * Rule processor that compares against the status of another note. + * + * @deprecated 8.8.0 */ -class NoteStatusRuleProcessor implements RuleProcessorInterface { +class NoteStatusRuleProcessor extends DeprecatedClassFacade { /** - * Compare against the status of another note. + * The name of the non-deprecated class that this facade covers. * - * @param object $rule The rule being processed by this rule processor. - * @param object $stored_state Stored state. - * - * @return bool The result of the operation. + * @var string */ - public function process( $rule, $stored_state ) { - $status = Notes::get_note_status( $rule->note_name ); - if ( ! $status ) { - return false; - } - - return ComparisonOperation::compare( - $status, - $rule->status, - $rule->operation - ); - } + protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\NoteStatusRuleProcessor'; /** - * Validates the rule. - * - * @param object $rule The rule to validate. + * The version that this class was deprecated in. * - * @return bool Pass/fail. + * @var string */ - public function validate( $rule ) { - if ( ! isset( $rule->note_name ) ) { - return false; - } - - if ( ! isset( $rule->status ) ) { - return false; - } - - if ( ! isset( $rule->operation ) ) { - return false; - } - - return true; - } + protected static $deprecated_in_version = '8.8.0'; } diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/OnboardingProfileRuleProcessor.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/OnboardingProfileRuleProcessor.php index b6ec890eb3f6..8697fb1ad1ed 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/OnboardingProfileRuleProcessor.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/OnboardingProfileRuleProcessor.php @@ -8,58 +8,26 @@ defined( 'ABSPATH' ) || exit; +use Automattic\WooCommerce\Admin\DeprecatedClassFacade; + /** * Rule processor that performs a comparison operation against a value in the * onboarding profile. + * + * @deprecated 8.8.0 */ -class OnboardingProfileRuleProcessor implements RuleProcessorInterface { +class OnboardingProfileRuleProcessor extends DeprecatedClassFacade { /** - * Performs a comparison operation against a value in the onboarding - * profile. - * - * @param object $rule The rule being processed by this rule processor. - * @param object $stored_state Stored state. + * The name of the non-deprecated class that this facade covers. * - * @return bool The result of the operation. + * @var string */ - public function process( $rule, $stored_state ) { - $onboarding_profile = get_option( 'woocommerce_onboarding_profile' ); - - if ( empty( $onboarding_profile ) || ! is_array( $onboarding_profile ) ) { - return false; - } - - if ( ! isset( $onboarding_profile[ $rule->index ] ) ) { - return false; - } - - return ComparisonOperation::compare( - $onboarding_profile[ $rule->index ], - $rule->value, - $rule->operation - ); - } + protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\OnboardingProfileRuleProcessor'; /** - * Validates the rule. + * The version that this class was deprecated in. * - * @param object $rule The rule to validate. - * - * @return bool Pass/fail. + * @var string */ - public function validate( $rule ) { - if ( ! isset( $rule->index ) ) { - return false; - } - - if ( ! isset( $rule->value ) ) { - return false; - } - - if ( ! isset( $rule->operation ) ) { - return false; - } - - return true; - } + protected static $deprecated_in_version = '8.8.0'; } diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/OptionRuleProcessor.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/OptionRuleProcessor.php index 4c5d4b36370d..af73b079504c 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/OptionRuleProcessor.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/OptionRuleProcessor.php @@ -7,97 +7,25 @@ defined( 'ABSPATH' ) || exit; +use Automattic\WooCommerce\Admin\DeprecatedClassFacade; + /** * Rule processor that performs a comparison operation against an option value. + * + * @deprecated 8.8.0 */ -class OptionRuleProcessor implements RuleProcessorInterface { - /** - * Performs a comparison operation against the option value. - * - * @param object $rule The specific rule being processed by this rule processor. - * @param object $stored_state Stored state. - * - * @return bool The result of the operation. - */ - public function process( $rule, $stored_state ) { - $is_contains = $rule->operation && strpos( $rule->operation, 'contains' ) !== false; - $default_value = $is_contains ? array() : false; - $is_default_set = property_exists( $rule, 'default' ); - $default = $is_default_set ? $rule->default : $default_value; - $option_value = $this->get_option_value( $rule, $default, $is_contains ); - - if ( isset( $rule->transformers ) && is_array( $rule->transformers ) ) { - $option_value = TransformerService::apply( $option_value, $rule->transformers, $is_default_set, $default ); - } - - return ComparisonOperation::compare( - $option_value, - $rule->value, - $rule->operation - ); - } - +class OptionRuleProcessor extends DeprecatedClassFacade { /** - * Retrieves the option value and handles logging if necessary. + * The name of the non-deprecated class that this facade covers. * - * @param object $rule The specific rule being processed. - * @param mixed $default The default value. - * @param bool $is_contains Indicates whether the operation is "contains". - * - * @return mixed The option value. + * @var string */ - private function get_option_value( $rule, $default, $is_contains ) { - $option_value = get_option( $rule->option_name, $default ); - $is_contains_valid = $is_contains && ( is_array( $option_value ) || ( is_string( $option_value ) && is_string( $rule->value ) ) ); - - if ( $is_contains && ! $is_contains_valid ) { - $logger = wc_get_logger(); - $logger->warning( - sprintf( - 'ComparisonOperation "%s" option value "%s" is not an array, defaulting to empty array.', - $rule->operation, - $rule->option_name - ), - array( - 'option_value' => $option_value, - 'rule' => $rule, - ) - ); - $option_value = array(); - } - - return $option_value; - } + protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\OptionRuleProcessor'; /** - * Validates the rule. - * - * @param object $rule The rule to validate. + * The version that this class was deprecated in. * - * @return bool Pass/fail. + * @var string */ - public function validate( $rule ) { - if ( ! isset( $rule->option_name ) ) { - return false; - } - - if ( ! isset( $rule->value ) ) { - return false; - } - - if ( ! isset( $rule->operation ) ) { - return false; - } - - if ( isset( $rule->transformers ) && is_array( $rule->transformers ) ) { - foreach ( $rule->transformers as $transform_args ) { - $transformer = TransformerService::create_transformer( $transform_args->use ); - if ( ! $transformer->validate( $transform_args->arguments ) ) { - return false; - } - } - } - - return true; - } + protected static $deprecated_in_version = '8.8.0'; } diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/OrRuleProcessor.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/OrRuleProcessor.php index 6e0f81e1c023..36fc83808cdd 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/OrRuleProcessor.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/OrRuleProcessor.php @@ -8,66 +8,26 @@ defined( 'ABSPATH' ) || exit; +use Automattic\WooCommerce\Admin\DeprecatedClassFacade; + /** * Rule processor that performs an OR operation on the rule's left and right * operands. + * + * @deprecated 8.8.0 */ -class OrRuleProcessor implements RuleProcessorInterface { - - /** - * Rule evaluator to use. - * - * @var RuleEvaluator - */ - private $rule_evaluator; - - - /** - * Constructor. - * - * @param RuleEvaluator $rule_evaluator The rule evaluator to use. - */ - public function __construct( $rule_evaluator = null ) { - $this->rule_evaluator = null === $rule_evaluator - ? new RuleEvaluator() - : $rule_evaluator; - } - +class OrRuleProcessor extends DeprecatedClassFacade { /** - * Performs an OR operation on the rule's left and right operands. - * - * @param object $rule The specific rule being processed by this rule processor. - * @param object $stored_state Stored state. + * The name of the non-deprecated class that this facade covers. * - * @return bool The result of the operation. + * @var string */ - public function process( $rule, $stored_state ) { - foreach ( $rule->operands as $operand ) { - $evaluated_operand = $this->rule_evaluator->evaluate( - $operand, - $stored_state - ); - - if ( $evaluated_operand ) { - return true; - } - } - - return false; - } + protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\OrRuleProcessor'; /** - * Validates the rule. + * The version that this class was deprecated in. * - * @param object $rule The rule to validate. - * - * @return bool Pass/fail. + * @var string */ - public function validate( $rule ) { - if ( ! isset( $rule->operands ) || ! is_array( $rule->operands ) ) { - return false; - } - - return true; - } + protected static $deprecated_in_version = '8.8.0'; } diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/OrderCountRuleProcessor.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/OrderCountRuleProcessor.php index 3eb79ab03cba..1c48fc135aba 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/OrderCountRuleProcessor.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/OrderCountRuleProcessor.php @@ -7,63 +7,25 @@ defined( 'ABSPATH' ) || exit; +use Automattic\WooCommerce\Admin\DeprecatedClassFacade; + /** * Rule processor for publishing based on the number of orders. + * + * @deprecated 8.8.0 */ -class OrderCountRuleProcessor implements RuleProcessorInterface { - - /** - * The orders provider. - * - * @var OrdersProvider - */ - protected $orders_provider; - +class OrderCountRuleProcessor extends DeprecatedClassFacade { /** - * Constructor. + * The name of the non-deprecated class that this facade covers. * - * @param object $orders_provider The orders provider. + * @var string */ - public function __construct( $orders_provider = null ) { - $this->orders_provider = null === $orders_provider - ? new OrdersProvider() - : $orders_provider; - } + protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\OrderCountRuleProcessor'; /** - * Process the rule. + * The version that this class was deprecated in. * - * @param object $rule The rule to process. - * @param object $stored_state Stored state. - * - * @return bool Whether the rule passes or not. + * @var string */ - public function process( $rule, $stored_state ) { - $count = $this->orders_provider->get_order_count(); - - return ComparisonOperation::compare( - $count, - $rule->value, - $rule->operation - ); - } - - /** - * Validates the rule. - * - * @param object $rule The rule to validate. - * - * @return bool Pass/fail. - */ - public function validate( $rule ) { - if ( ! isset( $rule->value ) ) { - return false; - } - - if ( ! isset( $rule->operation ) ) { - return false; - } - - return true; - } + protected static $deprecated_in_version = '8.8.0'; } diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/OrdersProvider.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/OrdersProvider.php index 653edb5f2d6d..eff865f3adce 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/OrdersProvider.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/OrdersProvider.php @@ -7,30 +7,25 @@ defined( 'ABSPATH' ) || exit; +use Automattic\WooCommerce\Admin\DeprecatedClassFacade; + /** * Provider for order-related queries and operations. + * + * @deprecated 8.8.0 */ -class OrdersProvider { +class OrdersProvider extends DeprecatedClassFacade { /** - * Allowed order statuses for calculating milestones. + * The name of the non-deprecated class that this facade covers. * - * @var array + * @var string */ - protected $allowed_statuses = array( - 'pending', - 'processing', - 'completed', - ); + protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\OrdersProvider'; /** - * Returns the number of orders. + * The version that this class was deprecated in. * - * @return integer The number of orders. + * @var string */ - public function get_order_count() { - $status_counts = array_map( 'wc_orders_count', $this->allowed_statuses ); - $orders_count = array_sum( $status_counts ); - - return $orders_count; - } + protected static $deprecated_in_version = '8.8.0'; } diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/PassRuleProcessor.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/PassRuleProcessor.php index 0efd1c971d86..83d9398f51cd 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/PassRuleProcessor.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/PassRuleProcessor.php @@ -8,30 +8,25 @@ defined( 'ABSPATH' ) || exit; +use Automattic\WooCommerce\Admin\DeprecatedClassFacade; + /** * Rule processor that passes. + * + * @deprecated 8.8.0 */ -class PassRuleProcessor implements RuleProcessorInterface { +class PassRuleProcessor extends DeprecatedClassFacade { /** - * Passes the rule. - * - * @param object $rule The specific rule being processed by this rule processor. - * @param object $stored_state Stored state. + * The name of the non-deprecated class that this facade covers. * - * @return bool Always true. + * @var string */ - public function process( $rule, $stored_state ) { - return true; - } + protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\PassRuleProcessor'; /** - * Validates the rule. - * - * @param object $rule The rule to validate. + * The version that this class was deprecated in. * - * @return bool Pass/fail. + * @var string */ - public function validate( $rule ) { - return true; - } + protected static $deprecated_in_version = '8.8.0'; } diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/PluginVersionRuleProcessor.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/PluginVersionRuleProcessor.php index f564d9d432a1..7308ca914faa 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/PluginVersionRuleProcessor.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/PluginVersionRuleProcessor.php @@ -8,79 +8,26 @@ defined( 'ABSPATH' ) || exit; -use Automattic\WooCommerce\Admin\PluginsProvider\PluginsProvider; +use Automattic\WooCommerce\Admin\DeprecatedClassFacade; /** * Rule processor for sending when the provided plugin is activated and * matches the specified version. + * + * @deprecated 8.8.0 */ -class PluginVersionRuleProcessor implements RuleProcessorInterface { - - /** - * Plugins provider instance. - * - * @var PluginsProviderInterface - */ - private $plugins_provider; - - - /** - * Constructor. - * - * @param PluginsProviderInterface $plugins_provider The plugins provider. - */ - public function __construct( $plugins_provider = null ) { - $this->plugins_provider = null === $plugins_provider - ? new PluginsProvider() - : $plugins_provider; - } - +class PluginVersionRuleProcessor extends DeprecatedClassFacade { /** - * Process the rule. + * The name of the non-deprecated class that this facade covers. * - * @param object $rule The specific rule being processed by this rule processor. - * @param object $stored_state Stored state. - * - * @return bool Whether the rule passes or not. + * @var string */ - public function process( $rule, $stored_state ) { - $active_plugin_slugs = $this->plugins_provider->get_active_plugin_slugs(); - - if ( ! in_array( $rule->plugin, $active_plugin_slugs, true ) ) { - return false; - } - - $plugin_data = $this->plugins_provider->get_plugin_data( $rule->plugin ); - - if ( ! is_array( $plugin_data ) || ! array_key_exists( 'Version', $plugin_data ) ) { - return false; - } - - $plugin_version = $plugin_data['Version']; - - return version_compare( $plugin_version, $rule->version, $rule->operator ); - } + protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\PluginVersionRuleProcessor'; /** - * Validates the rule. - * - * @param object $rule The rule to validate. + * The version that this class was deprecated in. * - * @return bool Pass/fail. + * @var string */ - public function validate( $rule ) { - if ( ! isset( $rule->plugin ) ) { - return false; - } - - if ( ! isset( $rule->version ) ) { - return false; - } - - if ( ! isset( $rule->operator ) ) { - return false; - } - - return true; - } + protected static $deprecated_in_version = '8.8.0'; } diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/PluginsActivatedRuleProcessor.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/PluginsActivatedRuleProcessor.php index fa41fa5699e5..490d6cebc8dc 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/PluginsActivatedRuleProcessor.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/PluginsActivatedRuleProcessor.php @@ -7,75 +7,25 @@ defined( 'ABSPATH' ) || exit; -use Automattic\WooCommerce\Admin\PluginsProvider\PluginsProvider; +use Automattic\WooCommerce\Admin\DeprecatedClassFacade; /** * Rule processor for sending when the provided plugins are activated. + * + * @deprecated 8.8.0 */ -class PluginsActivatedRuleProcessor implements RuleProcessorInterface { - - /** - * The plugins provider. - * - * @var PluginsProviderInterface - */ - protected $plugins_provider; - - /** - * Constructor. - * - * @param PluginsProviderInterface $plugins_provider The plugins provider. - */ - public function __construct( $plugins_provider = null ) { - $this->plugins_provider = null === $plugins_provider - ? new PluginsProvider() - : $plugins_provider; - } - +class PluginsActivatedRuleProcessor extends DeprecatedClassFacade { /** - * Process the rule. - * - * @param object $rule The specific rule being processed by this rule processor. - * @param object $stored_state Stored state. + * The name of the non-deprecated class that this facade covers. * - * @return bool Whether the rule passes or not. + * @var string */ - public function process( $rule, $stored_state ) { - if ( ! is_countable( $rule->plugins ) || 0 === count( $rule->plugins ) ) { - return false; - } - - $active_plugin_slugs = $this->plugins_provider->get_active_plugin_slugs(); - - foreach ( $rule->plugins as $plugin_slug ) { - if ( ! is_string( $plugin_slug ) ) { - $logger = wc_get_logger(); - $logger->warning( - __( 'Invalid plugin slug provided in the plugins activated rule.', 'woocommerce' ) - ); - return false; - } - - if ( ! in_array( $plugin_slug, $active_plugin_slugs, true ) ) { - return false; - } - } - - return true; - } + protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\PluginsActivatedRuleProcessor'; /** - * Validates the rule. + * The version that this class was deprecated in. * - * @param object $rule The rule to validate. - * - * @return bool Pass/fail. + * @var string */ - public function validate( $rule ) { - if ( ! isset( $rule->plugins ) || ! is_array( $rule->plugins ) ) { - return false; - } - - return true; - } + protected static $deprecated_in_version = '8.8.0'; } diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/ProductCountRuleProcessor.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/ProductCountRuleProcessor.php index 6742efe13161..c03e53d3b70d 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/ProductCountRuleProcessor.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/ProductCountRuleProcessor.php @@ -8,71 +8,26 @@ defined( 'ABSPATH' ) || exit; +use Automattic\WooCommerce\Admin\DeprecatedClassFacade; + /** * Rule processor that performs a comparison operation against the number of * products. + * + * @deprecated 8.8.0 */ -class ProductCountRuleProcessor implements RuleProcessorInterface { - - /** - * The product query. - * - * @var WC_Product_Query - */ - protected $product_query; - +class ProductCountRuleProcessor extends DeprecatedClassFacade { /** - * Constructor. + * The name of the non-deprecated class that this facade covers. * - * @param object $product_query The product query. + * @var string */ - public function __construct( $product_query = null ) { - $this->product_query = null === $product_query - ? new \WC_Product_Query( - array( - 'limit' => 1, - 'paginate' => true, - 'return' => 'ids', - 'status' => array( 'publish' ), - ) - ) - : $product_query; - } + protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\ProductCountRuleProcessor'; /** - * Performs a comparison operation against the number of products. + * The version that this class was deprecated in. * - * @param object $rule The specific rule being processed by this rule processor. - * @param object $stored_state Stored state. - * - * @return bool The result of the operation. + * @var string */ - public function process( $rule, $stored_state ) { - $products = $this->product_query->get_products(); - - return ComparisonOperation::compare( - $products->total, - $rule->value, - $rule->operation - ); - } - - /** - * Validates the rule. - * - * @param object $rule The rule to validate. - * - * @return bool Pass/fail. - */ - public function validate( $rule ) { - if ( ! isset( $rule->value ) ) { - return false; - } - - if ( ! isset( $rule->operation ) ) { - return false; - } - - return true; - } + protected static $deprecated_in_version = '8.8.0'; } diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/PublishAfterTimeRuleProcessor.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/PublishAfterTimeRuleProcessor.php index 75ad931400f8..98da25f08743 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/PublishAfterTimeRuleProcessor.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/PublishAfterTimeRuleProcessor.php @@ -7,61 +7,25 @@ defined( 'ABSPATH' ) || exit; -use Automattic\WooCommerce\Admin\DateTimeProvider\CurrentDateTimeProvider; +use Automattic\WooCommerce\Admin\DeprecatedClassFacade; /** * Rule processor for sending after a specified date/time. + * + * @deprecated 8.8.0 */ -class PublishAfterTimeRuleProcessor implements RuleProcessorInterface { - +class PublishAfterTimeRuleProcessor extends DeprecatedClassFacade { /** - * The DateTime provider. + * The name of the non-deprecated class that this facade covers. * - * @var DateTimeProviderInterface + * @var string */ - protected $date_time_provider; + protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\PublishAfterTimeRuleProcessor'; /** - * Constructor. + * The version that this class was deprecated in. * - * @param DateTimeProviderInterface $date_time_provider The DateTime provider. + * @var string */ - public function __construct( $date_time_provider = null ) { - $this->date_time_provider = null === $date_time_provider - ? new CurrentDateTimeProvider() - : $date_time_provider; - } - - /** - * Process the rule. - * - * @param object $rule The specific rule being processed by this rule processor. - * @param object $stored_state Stored state. - * - * @return bool Whether the rule passes or not. - */ - public function process( $rule, $stored_state ) { - return $this->date_time_provider->get_now() >= new \DateTime( $rule->publish_after ); - } - - /** - * Validates the rule. - * - * @param object $rule The rule to validate. - * - * @return bool Pass/fail. - */ - public function validate( $rule ) { - if ( ! isset( $rule->publish_after ) ) { - return false; - } - - try { - new \DateTime( $rule->publish_after ); - } catch ( \Throwable $e ) { - return false; - } - - return true; - } + protected static $deprecated_in_version = '8.8.0'; } diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/PublishBeforeTimeRuleProcessor.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/PublishBeforeTimeRuleProcessor.php index 9cde77c98b0e..3d36d6e6bcd4 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/PublishBeforeTimeRuleProcessor.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/PublishBeforeTimeRuleProcessor.php @@ -7,61 +7,25 @@ defined( 'ABSPATH' ) || exit; -use Automattic\WooCommerce\Admin\DateTimeProvider\CurrentDateTimeProvider; +use Automattic\WooCommerce\Admin\DeprecatedClassFacade; /** * Rule processor for sending before a specified date/time. + * + * @deprecated 8.8.0 */ -class PublishBeforeTimeRuleProcessor implements RuleProcessorInterface { - +class PublishBeforeTimeRuleProcessor extends DeprecatedClassFacade { /** - * The DateTime provider. + * The name of the non-deprecated class that this facade covers. * - * @var DateTimeProviderInterface + * @var string */ - protected $date_time_provider; + protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\PublishBeforeTimeRuleProcessor'; /** - * Constructor. + * The version that this class was deprecated in. * - * @param DateTimeProviderInterface $date_time_provider The DateTime provider. + * @var string */ - public function __construct( $date_time_provider = null ) { - $this->date_time_provider = null === $date_time_provider - ? new CurrentDateTimeProvider() - : $date_time_provider; - } - - /** - * Process the rule. - * - * @param object $rule The specific rule being processed by this rule processor. - * @param object $stored_state Stored state. - * - * @return bool Whether the rule passes or not. - */ - public function process( $rule, $stored_state ) { - return $this->date_time_provider->get_now() <= new \DateTime( $rule->publish_before ); - } - - /** - * Validates the rule. - * - * @param object $rule The rule to validate. - * - * @return bool Pass/fail. - */ - public function validate( $rule ) { - if ( ! isset( $rule->publish_before ) ) { - return false; - } - - try { - new \DateTime( $rule->publish_before ); - } catch ( \Throwable $e ) { - return false; - } - - return true; - } + protected static $deprecated_in_version = '8.8.0'; } diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/README.md b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/README.md index 92f7d0a58c5f..216c15d2d1d5 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/README.md +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/README.md @@ -136,480 +136,4 @@ The `status` is what the status of the created note will be set to after interac ## Rule -Rules in an array are executed as an AND operation. If there are no rules in the array the result is false and the specified notification is not shown. - -### Operations - -Some rule types support an `operation` value, which is used to compare two -values. The following operations are implemented: - -- `=` -- `<` -- `<=` -- `>` -- `>=` -- `!=` -- `contains` -- `!contains` -- `in` (Added in WooCommerce 8.2.0) -- `!in` (Added in WooCommerce 8.2.0) -- `range` (Added in WooCommerce 8.8.0) - -#### contains and !contains - -`contains` and `!contains` allow checking if the provided value is present (or -not present) in the haystack value. An example of this is using the -`onboarding_profile` rule to match on a value in the `product_types` array - -this rule matches if `physical` was selected as a product type in the -onboarding profile: - -```json -{ - "type": "onboarding_profile", - "index": "product_types", - "operation": "contains", - "value": "physical" -} -``` - -#### in and !in - -`in` and `!in` allow checking if a value is found (or not found) in a provided array. For example, using the `in` comparison operator to check if the base country location value is found in a given array, as below. This rule matches if the `base_location_country` is `US`, `NZ`, or `ZA`. **NOTE:** These comparisons were added in **WooCommerce 8.2.0**. If the spec is read by an older version of WooCommerce, the rule will evaluate to `false`. - -```json -{ - "type": "base_location_country", - "value": [ - "US", - "NZ", - "ZA" - ], - "operation": "in" -} -``` - -#### range - -`range` operator performs an inclusive check to determine if a number falls within a certain range. -This means that both the 'from' and 'to' values of the specified range are included in the check. - -The following rule returns true when `woocommerce_remote_variant_assignment` value is between 1 and 10. - -```json -{ - "type": "option", - "value": [ 1, 10 ], - "default": 0, - "operation": "range", - "option_name": "woocommerce_remote_variant_assignment", -} -``` - -### Plugins activated - -This passes if all of the listed plugins are installed and activated. - -`plugins` is required. - -```json -{ - "type": "plugins_activated", - "plugins": [ - "plugin-slug-1', - "plugin-slug-2" - ] -} -``` - -### Publish after time - -This passes if the system time is after the specified date/time. - -Note that using both `publish_after_time` and `publish_before_time` allows timeboxing a note which could be useful for promoting a sale. - -`publish_after` is required. - -```json -{ - "type": "publish_after_time", - "publish_after": "2020-04-22 00:00:00" -} -``` - -### Publish before time - -This passes if the system time is before the specified date/time. - -Note that using both `publish_after_time` and `publish_before_time` allows timeboxing a note which could be useful for promoting a sale. - -`publish_before` is required. - -```json -{ - "type": "publish_before_time", - "publish_before": "2020-04-22 00:00:00" -} -``` - -### Not - -This negates the rules in the provided set of rules. Note that the rules in `operand` get ANDed together into a single boolean. - -`operand` is required. - -```json -{ - "type": "not", - "operand": [ - , - ... - ] -} -``` - -### Or - -This performs an OR operation on the operands, passing if any of the operands evaluates to true. Note that if the operands are an array of `Rule`s (as in the first example), each operand is treated as an AND operation. - -`operands` is required. - -```json -{ - "type": "or", - "operands": [ - [ - , - ... - ], - [ - , - ... - ] - ] -} -``` - -Alternatively: - -```json -{ - "type": "or", - "operands": [ - , - ... - ] -} -``` - -### Fail - -This just returns a false value. This is useful if you want to keep a specification around, but don't want it displayed. - -```json -{ - "type": "fail" -} -``` - -### Plugin version - -This compares the installed version of the plugin to the required version, using the comparison operator. If the plugin isn’t activated this returns false. - -`plugin`, `version`, and `operator` are required. - -This example passes if Jetpack 8.4.1 is installed and activated. - -```json -{ - "type": "plugin_version", - "plugin": "jetpack", - "version": "8.4.1", - "operator": "=" -} -``` - -### Stored state - -This allows access to a stored state containing calculated values that otherwise would be impossible to reproduce using other rules. It performs the comparison operation against the stored state value. - -This example passes if the `there_were_no_products` index is equal to `true`. - -```json -{ - "type": "stored_state", - "index": "there_were_no_products", - "operation": "=", - "value": true -} -``` - -There are only a limited amount of indices available to this rule, and new indices will need a new version of the WC Admin plugin to be installed. - -The currently available indices are: - -```json -there_were_no_products -there_are_now_products -new_product_count -``` - -`index`, `operation`, and `value` are required. - -### Product count - -This passes if the number of products currently in the system match the comparison operation. - -This example passes if there are more than 10 products currently in the system. - -```json -{ - "type": "product_count", - "operation": ">", - "value": 10 -} -``` - -`operation` and `value` are required. - -### Order count - -This passes if the number of orders currently in the system match the comparison operation. - -This example passes if there are more than 10 orders currently in the system. - -```json -{ - "type": "order_count", - "operation": ">", - "value": 10 -} -``` - -`operation` and `value` are required. - -### WooCommerce Admin active for - -This passes if the time WooCommerce Admin has been active for (in days) matches the comparison operation. - -This is used as a proxy indicator of the age of the shop. - -This example passes if it has been active for more than 8 days. - -```json -{ - "type": "wcadmin_active_for", - "operation": ">", - "days": 8 -} -``` - -`operation` and `days` are required. - -### Onboarding profile - -This allows access to the onboarding profile that was built up in the onboarding wizard. The below example passes when the current revenue selected was "none". - -```json -{ - "type": "onboarding_profile", - "index": "revenue", - "operation": "=", - "value": "none" -} -``` - -`index`, `operation`, and `value` are all required. - -### Is eCommerce - -This passes when the store is on a WordPress.com site with the eCommerce plan. - -```json -{ - "type": "is_ecommerce", - "value": true -} -``` - -`value` is required. - -### Is Woo Express - -This passes when the store is on a WordPress.com site with a Woo Express plan active. -You can optionally pass the `plan` name to target a specific Woo Express plan, e.g. `performance`. - -```json -{ - "type": "is_woo_express", - "plan": "trial|essential|performance", - "value": true -} -``` - -`value` is required. -`plan` is optional, e.g. `trial`, `essential`, `performance`. - -### Base location - country - -This passes when the store is located in the specified country. - -```json -{ - "type": "base_location_country", - "value": "US", - "operation": "=" -} -``` - -`value` and `operation` are both required. - -### Base location - state - -This passes when the store is located in the specified state. - -```json -{ - "type": "base_location_state", - "value": "TX", - "operation": "=" -} -``` - -`value` and `operation` are both required. - -### Note status - -This passes when the status of the specified note matches the specified status. -The below example passes when the `wc-admin-mobile-app` note has not been -actioned. - -```json -{ - "type": "note_status", - "note_name": "wc-admin-mobile-app", - "status": "actioned", - "operation": "!=" -} -``` - -### Total Payments Value - -This passes when the total value of all payments for a given timeframe -compared to the provided value pass the operation test. - -`timeframe` can be one of `last_week`, `last_month`, `last_quarter`, `last_6_months`, `last_year` - -```json -{ - "type": "total_payments_value", - "timeframe": "last_month", - "value": 2300, - "operation": ">" -} -``` - -`timeframe`, `value`, and `operation` are all required. - -### Option - -This passes when the option value matches the value using the operation. - -```json -{ - "type": "option", - "option_name": "woocommerce_currency", - "value": "USD", - "default": "USD", - "operation": "=" -} -``` - -`option_name`, `value`, and `operation` are all required. `default` is not required and allows a default value to be used if the option does not exist. - -#### Option Transformer - -This transforms the given option value into a different value by a series of transformers. - -Example option value: - -```php -Array -( - [setup_client] => - [industry] => Array - ( - [0] => Array - ( - [slug] => food-drink - ) - - [1] => Array - ( - [slug] => fashion-apparel-accessories - ) - ) -) -``` - -If you want to ensure that the industry array contains `fashion-apparel-accessories`, you can use the following Option definition with transformers. - -```json -{ - "type": "option", - "transformers": [ - { - "use": "dot_notation", - "arguments": { - "path": "industry" - } - }, - { - "use": "array_column", - "arguments": { - "key": "slug" - } - }, - { - "use": "array_search", - "arguments": { - "value": "fashion-apparel-accessories" - } - } - ], - "option_name": "woocommerce_onboarding_profile", - "value": "fashion-apparel-accessories", - "default": "USD", - "operation": "=" -} -``` - -You can find a list of transformers and examples in the transformer [README](./Transformers/README.md). - -### WCA updated - -This passes when WooCommerce Admin has just been updated. The specs will be run -on update. Note that this doesn't provide a way to check the version number as -the `plugin_version` rule can be used to check for a specific version of the -WooCommerce Admin plugin. - -```json -{ - type: "wca_updated" -} -``` - -No other values are needed. - -## Debugging Specification - -You can see the evaluation of each specification by turning on an optional evaluation logger. - -1. Define `WC_ADMIN_DEBUG_RULE_EVALUATOR` constant in `wp-config.php`. `define('WC_ADMIN_DEBUG_RULE_EVALUATOR', true);` -2. Run `wc_admin_daily` -3. cd to `wp-content/uploads/wc-logs/` and check a log file in `remote-inbox-notifications-:date-hash.log` format. - -You can tail the log file with a slug name to see the evaluation of a rule that you are testing. - -Example: - -`tail -f remote-inbox-notifications-2021-06-15-128.log | grep 'wcpay-promo-2021-6-incentive-2'` +You can find the readme for RuleProcessors and Transformers in [this README](../RemoteSpecs/RuleProcessors/README.md) diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/DataSourcePoller.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/RemoteInboxNotificationsDataSourcePoller.php similarity index 96% rename from plugins/woocommerce/src/Admin/RemoteInboxNotifications/DataSourcePoller.php rename to plugins/woocommerce/src/Admin/RemoteInboxNotifications/RemoteInboxNotificationsDataSourcePoller.php index 96cd3dff5afb..606aa783497e 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/DataSourcePoller.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/RemoteInboxNotificationsDataSourcePoller.php @@ -7,12 +7,15 @@ defined( 'ABSPATH' ) || exit; +use Automattic\WooCommerce\Admin\RemoteSpecs\DataSourcePoller; +use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\GetRuleProcessor; + /** * Specs data source poller class. * This handles polling specs from JSON endpoints, and * stores the specs in to the database as an option. */ -class DataSourcePoller extends \Automattic\WooCommerce\Admin\DataSourcePoller { +class RemoteInboxNotificationsDataSourcePoller extends DataSourcePoller { const ID = 'remote_inbox_notifications'; const DATA_SOURCES = array( 'https://woocommerce.com/wp-json/wccom/inbox-notifications/2.0/notifications.json', diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/RemoteInboxNotificationsEngine.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/RemoteInboxNotificationsEngine.php index 7f8a91a43b14..8555ff9ba186 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/RemoteInboxNotificationsEngine.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/RemoteInboxNotificationsEngine.php @@ -11,6 +11,7 @@ use Automattic\WooCommerce\Internal\Admin\Onboarding\OnboardingProfile; use Automattic\WooCommerce\Admin\Notes\Note; use Automattic\WooCommerce\Admin\RemoteSpecs\RemoteSpecsEngine; +use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\StoredStateSetupForProducts; /** * Remote Inbox Notifications engine. @@ -111,7 +112,7 @@ public static function on_init() { * Go through the specs and run them. */ public static function run() { - $specs = DataSourcePoller::get_instance()->get_specs_from_data_sources(); + $specs = RemoteInboxNotificationsDataSourcePoller::get_instance()->get_specs_from_data_sources(); if ( false === $specs || ! is_countable( $specs ) || count( $specs ) === 0 ) { return; @@ -204,7 +205,7 @@ public static function get_note_from_db( $note_from_db ) { if ( ! $note_from_db instanceof Note || get_user_locale() === $note_from_db->get_locale() ) { return $note_from_db; } - $specs = DataSourcePoller::get_instance()->get_specs_from_data_sources(); + $specs = RemoteInboxNotificationsDataSourcePoller::get_instance()->get_specs_from_data_sources(); foreach ( $specs as $spec ) { if ( $spec->slug !== $note_from_db->get_name() ) { continue; diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/RuleEvaluator.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/RuleEvaluator.php index 09663461e82c..4c5189842639 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/RuleEvaluator.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/RuleEvaluator.php @@ -8,85 +8,26 @@ defined( 'ABSPATH' ) || exit; +use Automattic\WooCommerce\Admin\DeprecatedClassFacade; + /** * Evaluate the given rules as an AND operation - return false early if a * rule evaluates to false. + * + * @deprecated 8.8.0 */ -class RuleEvaluator { - - /** - * GetRuleProcessor to use. - * - * @var GetRuleProcessor - */ - private $get_rule_processor; - +class RuleEvaluator extends DeprecatedClassFacade { /** - * Constructor. + * The name of the non-deprecated class that this facade covers. * - * @param GetRuleProcessor $get_rule_processor The GetRuleProcessor to use. + * @var string */ - public function __construct( $get_rule_processor = null ) { - $this->get_rule_processor = null === $get_rule_processor - ? new GetRuleProcessor() - : $get_rule_processor; - } + protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\RuleEvaluator'; /** - * Evaluate the given rules as an AND operation - return false early if a - * rule evaluates to false. - * - * @param array|object $rules The rule or rules being processed. - * @param object|null $stored_state Stored state. - * @param array $logger_args Arguments for the event logger. `slug` is required. - * - * @throws \InvalidArgumentException Thrown when $logger_args is missing slug. + * The version that this class was deprecated in. * - * @return bool The result of the operation. + * @var string */ - public function evaluate( $rules, $stored_state = null, $logger_args = array() ) { - - if ( is_bool( $rules ) ) { - return $rules; - } - - if ( ! is_array( $rules ) ) { - $rules = array( $rules ); - } - - if ( 0 === count( $rules ) ) { - return false; - } - - $evaluation_logger = null; - - if ( count( $logger_args ) ) { - if ( ! array_key_exists( 'slug', $logger_args ) ) { - throw new \InvalidArgumentException( 'Missing required field: slug in $logger_args.' ); - } - - array_key_exists( 'source', $logger_args ) ? $source = $logger_args['source'] : $source = null; - - $evaluation_logger = new EvaluationLogger( $logger_args['slug'], $source ); - } - - foreach ( $rules as $rule ) { - if ( ! is_object( $rule ) ) { - return false; - } - - $processor = $this->get_rule_processor->get_processor( $rule->type ); - $processor_result = $processor->process( $rule, $stored_state ); - $evaluation_logger && $evaluation_logger->add_result( $rule->type, $processor_result ); - - if ( ! $processor_result ) { - $evaluation_logger && $evaluation_logger->log(); - return false; - } - } - - $evaluation_logger && $evaluation_logger->log(); - - return true; - } + protected static $deprecated_in_version = '8.8.0'; } diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/SpecRunner.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/SpecRunner.php index 5cb184891208..ab38100f3e9a 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/SpecRunner.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/SpecRunner.php @@ -9,6 +9,8 @@ use Automattic\WooCommerce\Admin\Notes\Note; use Automattic\WooCommerce\Admin\Notes\Notes; +use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\EvaluateAndGetStatus; +use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\RuleEvaluator; /** * Runs a single spec. diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/StoredStateRuleProcessor.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/StoredStateRuleProcessor.php index 0d179aa7e4d5..bc4f2c5e9fb0 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/StoredStateRuleProcessor.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/StoredStateRuleProcessor.php @@ -8,51 +8,26 @@ defined( 'ABSPATH' ) || exit; +use Automattic\WooCommerce\Admin\DeprecatedClassFacade; + /** * Rule processor that performs a comparison operation against a value in the * stored state object. + * + * @deprecated 8.8.0 */ -class StoredStateRuleProcessor implements RuleProcessorInterface { +class StoredStateRuleProcessor extends DeprecatedClassFacade { /** - * Performs a comparison operation against a value in the stored state object. - * - * @param object $rule The rule being processed by this rule processor. - * @param object $stored_state Stored state. + * The name of the non-deprecated class that this facade covers. * - * @return bool The result of the operation. + * @var string */ - public function process( $rule, $stored_state ) { - if ( ! isset( $stored_state->{$rule->index} ) ) { - return false; - } - - return ComparisonOperation::compare( - $stored_state->{$rule->index}, - $rule->value, - $rule->operation - ); - } + protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\StoredStateRuleProcessor'; /** - * Validates the rule. - * - * @param object $rule The rule to validate. + * The version that this class was deprecated in. * - * @return bool Pass/fail. + * @var string */ - public function validate( $rule ) { - if ( ! isset( $rule->index ) ) { - return false; - } - - if ( ! isset( $rule->value ) ) { - return false; - } - - if ( ! isset( $rule->operation ) ) { - return false; - } - - return true; - } + protected static $deprecated_in_version = '8.8.0'; } diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/StoredStateSetupForProducts.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/StoredStateSetupForProducts.php index 7efcbbd60808..f8b09f5a05a1 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/StoredStateSetupForProducts.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/StoredStateSetupForProducts.php @@ -7,125 +7,25 @@ defined( 'ABSPATH' ) || exit; -use Automattic\WooCommerce\Admin\PluginsProvider\PluginsProvider; -use Automattic\WooCommerce\Admin\RemoteInboxNotifications\SpecRunner; +use Automattic\WooCommerce\Admin\DeprecatedClassFacade; /** * Handles stored state setup for products. + * + * @deprecated 8.8.0 */ -class StoredStateSetupForProducts { - const ASYNC_RUN_REMOTE_NOTIFICATIONS_ACTION_NAME = - 'woocommerce_admin/stored_state_setup_for_products/async/run_remote_notifications'; - - /** - * Initialize the class via the admin_init hook. - */ - public static function admin_init() { - add_action( 'product_page_product_importer', array( __CLASS__, 'run_on_product_importer' ) ); - add_action( 'transition_post_status', array( __CLASS__, 'run_on_transition_post_status' ), 10, 3 ); - } - - /** - * Initialize the class via the init hook. - */ - public static function init() { - add_action( self::ASYNC_RUN_REMOTE_NOTIFICATIONS_ACTION_NAME, array( __CLASS__, 'run_remote_notifications' ) ); - } - +class StoredStateSetupForProducts extends DeprecatedClassFacade { /** - * Run the remote notifications engine. This is triggered by - * action-scheduler after a product is added. It also cleans up from - * setting the product count increment. - */ - public static function run_remote_notifications() { - RemoteInboxNotificationsEngine::run(); - } - - /** - * Set initial stored state values. - * - * @param object $stored_state The stored state. + * The name of the non-deprecated class that this facade covers. * - * @return object The stored state. + * @var string */ - public static function init_stored_state( $stored_state ) { - $stored_state->there_were_no_products = ! self::are_there_products(); - $stored_state->there_are_now_products = ! $stored_state->there_were_no_products; - - return $stored_state; - } + protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\StoredStateSetupForProducts'; /** - * Are there products query. + * The version that this class was deprecated in. * - * @return bool + * @var string */ - private static function are_there_products() { - $query = new \WC_Product_Query( - array( - 'limit' => 1, - 'paginate' => true, - 'return' => 'ids', - 'status' => array( 'publish' ), - ) - ); - $products = $query->get_products(); - $count = $products->total; - - return $count > 0; - } - - /** - * Runs on product importer steps. - */ - public static function run_on_product_importer() { - // We're only interested in when the importer completes. - // phpcs:disable WordPress.Security.NonceVerification.Recommended - if ( ! isset( $_REQUEST['step'] ) ) { - return; - } - if ( 'done' !== $_REQUEST['step'] ) { - return; - } - // phpcs:enable - - self::update_stored_state_and_possibly_run_remote_notifications(); - } - - /** - * Runs when a post status transitions, but we're only interested if it is - * a product being published. - * - * @param string $new_status The new status. - * @param string $old_status The old status. - * @param Post $post The post. - */ - public static function run_on_transition_post_status( $new_status, $old_status, $post ) { - if ( - 'product' !== $post->post_type || - 'publish' !== $new_status - ) { - return; - } - - self::update_stored_state_and_possibly_run_remote_notifications(); - } - - /** - * Enqueues an async action (using action-scheduler) to run remote - * notifications. - */ - private static function update_stored_state_and_possibly_run_remote_notifications() { - $stored_state = RemoteInboxNotificationsEngine::get_stored_state(); - // If the stored_state is the same, we don't need to run remote notifications to avoid unnecessary action scheduling. - if ( true === $stored_state->there_are_now_products ) { - return; - } - - $stored_state->there_are_now_products = true; - RemoteInboxNotificationsEngine::update_stored_state( $stored_state ); - - // Run self::run_remote_notifications asynchronously. - as_enqueue_async_action( self::ASYNC_RUN_REMOTE_NOTIFICATIONS_ACTION_NAME ); - } + protected static $deprecated_in_version = '8.8.0'; } diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/TotalPaymentsVolumeProcessor.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/TotalPaymentsVolumeProcessor.php index 03f14eac5861..cb1f1d0fc907 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/TotalPaymentsVolumeProcessor.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/TotalPaymentsVolumeProcessor.php @@ -7,87 +7,25 @@ defined( 'ABSPATH' ) || exit; -use Automattic\WooCommerce\Admin\API\Reports\Revenue\Query as RevenueQuery; -use Automattic\WooCommerce\Admin\API\Reports\TimeInterval; +use Automattic\WooCommerce\Admin\DeprecatedClassFacade; /** * Rule processor that passes when a store's payments volume exceeds a provided amount. + * + * @deprecated 8.8.0 */ -class TotalPaymentsVolumeProcessor implements RuleProcessorInterface { +class TotalPaymentsVolumeProcessor extends DeprecatedClassFacade { /** - * Compare against the store's total payments volume. + * The name of the non-deprecated class that this facade covers. * - * @param object $rule The rule being processed by this rule processor. - * @param object $stored_state Stored state. - * - * @return bool The result of the operation. - */ - public function process( $rule, $stored_state ) { - $dates = TimeInterval::get_timeframe_dates( $rule->timeframe ); - $reports_revenue = $this->get_reports_query( - array( - 'before' => $dates['end'], - 'after' => $dates['start'], - 'interval' => 'year', - 'fields' => array( 'total_sales' ), - ) - ); - $report_data = $reports_revenue->get_data(); - - if ( ! $report_data || ! isset( $report_data->totals->total_sales ) ) { - return false; - } - - $value = $report_data->totals->total_sales; - - return ComparisonOperation::compare( - $value, - $rule->value, - $rule->operation - ); - } - - /** - * Validates the rule. - * - * @param object $rule The rule to validate. - * - * @return bool Pass/fail. + * @var string */ - public function validate( $rule ) { - $allowed_timeframes = array( - 'last_week', - 'last_month', - 'last_quarter', - 'last_6_months', - 'last_year', - ); - - if ( ! isset( $rule->timeframe ) || ! in_array( $rule->timeframe, $allowed_timeframes, true ) ) { - return false; - } - - if ( ! isset( $rule->value ) || ! is_numeric( $rule->value ) ) { - return false; - } - - if ( ! isset( $rule->operation ) ) { - return false; - } - - return true; - } + protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\TotalPaymentsVolumeProcessor'; /** - * Get the report query. - * - * @param array $args The query args. + * The version that this class was deprecated in. * - * @return RevenueQuery The report query. + * @var string */ - protected function get_reports_query( $args ) { - return new RevenueQuery( - $args - ); - } + protected static $deprecated_in_version = '8.8.0'; } diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/TransformerInterface.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/TransformerInterface.php index 419b6e9f6de9..91efd1c2906b 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/TransformerInterface.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/TransformerInterface.php @@ -17,11 +17,11 @@ interface TransformerInterface { * * @param mixed $value a value to transform. * @param stdClass|null $arguments arguments. - * @param string|null $default default value. + * @param string|null $default_value default value. * * @return mixed|null */ - public function transform( $value, stdClass $arguments = null, $default = null); + public function transform( $value, stdClass $arguments = null, $default_value = null ); /** * Validate Transformer arguments. diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/TransformerService.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/TransformerService.php index 265177dd3e95..eafd3ee7f801 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/TransformerService.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/TransformerService.php @@ -2,8 +2,7 @@ namespace Automattic\WooCommerce\Admin\RemoteInboxNotifications; -use InvalidArgumentException; -use stdClass; +use Automattic\WooCommerce\Admin\DeprecatedClassFacade; /** * A simple service class for the Transformer classes. @@ -11,73 +10,21 @@ * Class TransformerService * * @package Automattic\WooCommerce\Admin\RemoteInboxNotifications + * + * @deprecated 8.8.0 */ -class TransformerService { +class TransformerService extends DeprecatedClassFacade { /** - * Create a transformer object by name. - * - * @param string $name name of the transformer. + * The name of the non-deprecated class that this facade covers. * - * @return TransformerInterface|null + * @var string */ - public static function create_transformer( $name ) { - $camel_cased = str_replace( ' ', '', ucwords( str_replace( '_', ' ', $name ) ) ); - - $classname = __NAMESPACE__ . '\\Transformers\\' . $camel_cased; - if ( ! class_exists( $classname ) ) { - return null; - } - - return new $classname(); - } + protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers\TransformerService'; /** - * Apply transformers to the given value. - * - * @param mixed $target_value a value to transform. - * @param array $transformer_configs transform configuration. - * @param bool $is_default_set flag on is default value set. - * @param string $default default value. + * The version that this class was deprecated in. * - * @throws InvalidArgumentException Throws when one of the requried arguments is missing. - * @return mixed|null + * @var string */ - public static function apply( $target_value, array $transformer_configs, $is_default_set, $default ) { - foreach ( $transformer_configs as $transformer_config ) { - if ( ! isset( $transformer_config->use ) ) { - throw new InvalidArgumentException( 'Missing required config value: use' ); - } - - if ( ! isset( $transformer_config->arguments ) ) { - $transformer_config->arguments = null; - } - - $transformer = self::create_transformer( $transformer_config->use ); - if ( null === $transformer ) { - throw new InvalidArgumentException( "Unable to find a transformer by name: {$transformer_config->use}" ); - } - - $target_value = $transformer->transform( $target_value, $transformer_config->arguments, $is_default_set ? $default : null ); - - // Break early when there's no more value to traverse. - if ( null === $target_value ) { - break; - } - } - - if ( $is_default_set ) { - // Nulls always return the default value. - if ( null === $target_value ) { - return $default; - } - - // When type of the default value is different from the target value, return the default value - // to ensure type safety. - if ( gettype( $default ) !== gettype( $target_value ) ) { - return $default; - } - } - - return $target_value; - } + protected static $deprecated_in_version = '8.8.0'; } diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/Transformers/ArrayColumn.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/Transformers/ArrayColumn.php index 8904bc9428ba..858b8a869d9a 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/Transformers/ArrayColumn.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/Transformers/ArrayColumn.php @@ -2,55 +2,27 @@ namespace Automattic\WooCommerce\Admin\RemoteInboxNotifications\Transformers; -use Automattic\WooCommerce\Admin\RemoteInboxNotifications\TransformerInterface; -use InvalidArgumentException; -use stdClass; +use Automattic\WooCommerce\Admin\DeprecatedClassFacade; /** * Search array value by one of its key. * * @package Automattic\WooCommerce\Admin\RemoteInboxNotifications\Transformers + * + * @deprecated 8.8.0 */ -class ArrayColumn implements TransformerInterface { +class ArrayColumn extends DeprecatedClassFacade { /** - * Search array value by one of its key. - * - * @param mixed $value a value to transform. - * @param stdClass|null $arguments required arguments 'key'. - * @param string|null $default default value. + * The name of the non-deprecated class that this facade covers. * - * @throws InvalidArgumentException Throws when the required argument 'key' is missing. - * - * @return mixed + * @var string */ - public function transform( $value, stdClass $arguments = null, $default = array() ) { - if ( ! is_array( $value ) ) { - return $default; - } - - return array_column( $value, $arguments->key ); - } + protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers\ArrayColumn'; /** - * Validate Transformer arguments. + * The version that this class was deprecated in. * - * @param stdClass|null $arguments arguments to validate. - * - * @return mixed + * @var string */ - public function validate( stdClass $arguments = null ) { - if ( ! isset( $arguments->key ) ) { - return false; - } - - if ( - null !== $arguments->key && - ! is_string( $arguments->key ) && - ! is_int( $arguments->key ) - ) { - return false; - } - - return true; - } + protected static $deprecated_in_version = '8.8.0'; } diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/Transformers/ArrayFlatten.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/Transformers/ArrayFlatten.php index 7f1050fdfd8a..741c06a8da18 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/Transformers/ArrayFlatten.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/Transformers/ArrayFlatten.php @@ -2,48 +2,27 @@ namespace Automattic\WooCommerce\Admin\RemoteInboxNotifications\Transformers; -use Automattic\WooCommerce\Admin\RemoteInboxNotifications\TransformerInterface; -use stdClass; +use Automattic\WooCommerce\Admin\DeprecatedClassFacade; /** * Flatten nested array. * * @package Automattic\WooCommerce\Admin\RemoteInboxNotifications\Transformers + * + * @deprecated 8.8.0 */ -class ArrayFlatten implements TransformerInterface { +class ArrayFlatten extends DeprecatedClassFacade { /** - * Search a given value in the array. - * - * @param mixed $value a value to transform. - * @param stdClass|null $arguments arguments. - * @param string|null $default default value. + * The name of the non-deprecated class that this facade covers. * - * @return mixed|null + * @var string */ - public function transform( $value, stdClass $arguments = null, $default = array() ) { - if ( ! is_array( $value ) ) { - return $default; - } - - $return = array(); - array_walk_recursive( - $value, - function( $item ) use ( &$return ) { - $return[] = $item; - } - ); - - return $return; - } + protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers\ArrayColumn'; /** - * Validate Transformer arguments. - * - * @param stdClass|null $arguments arguments to validate. + * The version that this class was deprecated in. * - * @return mixed + * @var string */ - public function validate( stdClass $arguments = null ) { - return true; - } + protected static $deprecated_in_version = '8.8.0'; } diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/Transformers/ArrayKeys.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/Transformers/ArrayKeys.php index fbd7c7d8ebc8..af262c96f710 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/Transformers/ArrayKeys.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/Transformers/ArrayKeys.php @@ -2,40 +2,27 @@ namespace Automattic\WooCommerce\Admin\RemoteInboxNotifications\Transformers; -use Automattic\WooCommerce\Admin\RemoteInboxNotifications\TransformerInterface; -use stdClass; +use Automattic\WooCommerce\Admin\DeprecatedClassFacade; /** * Search array value by one of its key. * * @package Automattic\WooCommerce\Admin\RemoteInboxNotifications\Transformers + * + * @deprecated 8.8.0 */ -class ArrayKeys implements TransformerInterface { +class ArrayKeys extends DeprecatedClassFacade { /** - * Search array value by one of its key. - * - * @param mixed $value a value to transform. - * @param stdClass|null $arguments arguments. - * @param string|null $default default value. + * The name of the non-deprecated class that this facade covers. * - * @return mixed + * @var string */ - public function transform( $value, stdClass $arguments = null, $default = array() ) { - if ( ! is_array( $value ) ) { - return $default; - } - - return array_keys( $value ); - } + protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers\ArrayColumn'; /** - * Validate Transformer arguments. - * - * @param stdClass|null $arguments arguments to validate. + * The version that this class was deprecated in. * - * @return mixed + * @var string */ - public function validate( stdClass $arguments = null ) { - return true; - } + protected static $deprecated_in_version = '8.8.0'; } diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/Transformers/ArraySearch.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/Transformers/ArraySearch.php index dafda9a0b31e..2ef9a9f8b202 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/Transformers/ArraySearch.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/Transformers/ArraySearch.php @@ -2,52 +2,27 @@ namespace Automattic\WooCommerce\Admin\RemoteInboxNotifications\Transformers; -use Automattic\WooCommerce\Admin\RemoteInboxNotifications\TransformerInterface; -use InvalidArgumentException; -use stdClass; +use Automattic\WooCommerce\Admin\DeprecatedClassFacade; /** * Searches a given a given value in the array. * * @package Automattic\WooCommerce\Admin\RemoteInboxNotifications\Transformers + * + * @deprecated 8.8.0 */ -class ArraySearch implements TransformerInterface { +class ArraySearch extends DeprecatedClassFacade { /** - * Search a given value in the array. - * - * @param mixed $value a value to transform. - * @param stdClass|null $arguments required argument 'value'. - * @param string|null $default default value. + * The name of the non-deprecated class that this facade covers. * - * @throws InvalidArgumentException Throws when the required 'value' is missing. - * - * @return mixed|null + * @var string */ - public function transform( $value, stdClass $arguments = null, $default = null ) { - if ( ! is_array( $value ) ) { - return $default; - } - - $key = array_search( $arguments->value, $value, true ); - if ( false !== $key ) { - return $value[ $key ]; - } - - return null; - } + protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers\ArrayColumn'; /** - * Validate Transformer arguments. - * - * @param stdClass|null $arguments arguments to validate. + * The version that this class was deprecated in. * - * @return mixed + * @var string */ - public function validate( stdClass $arguments = null ) { - if ( ! isset( $arguments->value ) ) { - return false; - } - - return true; - } + protected static $deprecated_in_version = '8.8.0'; } diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/Transformers/ArrayValues.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/Transformers/ArrayValues.php index 503bf56fc853..ecbbf33b24b8 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/Transformers/ArrayValues.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/Transformers/ArrayValues.php @@ -2,40 +2,27 @@ namespace Automattic\WooCommerce\Admin\RemoteInboxNotifications\Transformers; -use Automattic\WooCommerce\Admin\RemoteInboxNotifications\TransformerInterface; -use stdClass; +use Automattic\WooCommerce\Admin\DeprecatedClassFacade; /** * Search array value by one of its key. * * @package Automattic\WooCommerce\Admin\RemoteInboxNotifications\Transformers + * + * @deprecated 8.8.0 */ -class ArrayValues implements TransformerInterface { +class ArrayValues extends DeprecatedClassFacade { /** - * Search array value by one of its key. - * - * @param mixed $value a value to transform. - * @param stdClass|null $arguments arguments. - * @param string|null $default default value. + * The name of the non-deprecated class that this facade covers. * - * @return mixed + * @var string */ - public function transform( $value, stdClass $arguments = null, $default = array() ) { - if ( ! is_array( $value ) ) { - return $default; - } - - return array_values( $value ); - } + protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers\ArrayColumn'; /** - * Validate Transformer arguments. - * - * @param stdClass|null $arguments arguments to validate. + * The version that this class was deprecated in. * - * @return mixed + * @var string */ - public function validate( stdClass $arguments = null ) { - return true; - } + protected static $deprecated_in_version = '8.8.0'; } diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/Transformers/Count.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/Transformers/Count.php index f5b5edb14322..0be66f9becdd 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/Transformers/Count.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/Transformers/Count.php @@ -2,40 +2,27 @@ namespace Automattic\WooCommerce\Admin\RemoteInboxNotifications\Transformers; -use Automattic\WooCommerce\Admin\RemoteInboxNotifications\TransformerInterface; -use stdClass; +use Automattic\WooCommerce\Admin\DeprecatedClassFacade; /** * Count elements in Array or Countable object. * * @package Automattic\WooCommerce\Admin\RemoteInboxNotifications\Transformers + * + * @deprecated 8.8.0 */ -class Count implements TransformerInterface { +class Count extends DeprecatedClassFacade { /** - * Count elements in Array or Countable object. - * - * @param array|Countable $value an array to count. - * @param stdClass|null $arguments arguments. - * @param string|null $default default value. + * The name of the non-deprecated class that this facade covers. * - * @return number + * @var string */ - public function transform( $value, stdClass $arguments = null, $default = null ) { - if ( ! is_array( $value ) && ! $value instanceof \Countable ) { - return $default; - } - - return count( $value ); - } + protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers\ArrayColumn'; /** - * Validate Transformer arguments. - * - * @param stdClass|null $arguments arguments to validate. + * The version that this class was deprecated in. * - * @return mixed + * @var string */ - public function validate( stdClass $arguments = null ) { - return true; - } + protected static $deprecated_in_version = '8.8.0'; } diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/Transformers/DotNotation.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/Transformers/DotNotation.php index 78424bda7254..b8e3fcf87030 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/Transformers/DotNotation.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/Transformers/DotNotation.php @@ -2,78 +2,27 @@ namespace Automattic\WooCommerce\Admin\RemoteInboxNotifications\Transformers; -use Automattic\WooCommerce\Admin\RemoteInboxNotifications\TransformerInterface; -use InvalidArgumentException; -use stdClass; +use Automattic\WooCommerce\Admin\DeprecatedClassFacade; /** * Find an array value by dot notation. * * @package Automattic\WooCommerce\Admin\RemoteInboxNotifications\Transformers + * + * @deprecated 8.8.0 */ -class DotNotation implements TransformerInterface { - - /** - * Find given path from the given value. - * - * @param mixed $value a value to transform. - * @param stdClass|null $arguments required argument 'path'. - * @param string|null $default default value. - * - * @throws InvalidArgumentException Throws when the required 'path' is missing. - * - * @return mixed - */ - public function transform( $value, stdclass $arguments = null, $default = null ) { - if ( is_object( $value ) ) { - // if the value is an object, convert it to an array. - $value = json_decode( wp_json_encode( $value ), true ); - } - - return $this->get( $value, $arguments->path, $default ); - } - +class DotNotation extends DeprecatedClassFacade { /** - * Find the given $path in $array by dot notation. - * - * @param array $array an array to search in. - * @param string $path a path in the given array. - * @param null $default default value to return if $path was not found. + * The name of the non-deprecated class that this facade covers. * - * @return mixed|null + * @var string */ - public function get( $array, $path, $default = null ) { - if ( ! is_array( $array ) ) { - return $default; - } - - if ( isset( $array[ $path ] ) ) { - return $array[ $path ]; - } - - foreach ( explode( '.', $path ) as $segment ) { - if ( ! is_array( $array ) || ! array_key_exists( $segment, $array ) ) { - return $default; - } - - $array = $array[ $segment ]; - } - - return $array; - } + protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers\ArrayColumn'; /** - * Validate Transformer arguments. + * The version that this class was deprecated in. * - * @param stdClass|null $arguments arguments to validate. - * - * @return mixed + * @var string */ - public function validate( stdClass $arguments = null ) { - if ( ! isset( $arguments->path ) ) { - return false; - } - - return true; - } + protected static $deprecated_in_version = '8.8.0'; } diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/Transformers/PrepareUrl.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/Transformers/PrepareUrl.php index f04fdcfb8247..d8cc7150a8ec 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/Transformers/PrepareUrl.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/Transformers/PrepareUrl.php @@ -2,54 +2,27 @@ namespace Automattic\WooCommerce\Admin\RemoteInboxNotifications\Transformers; -use Automattic\WooCommerce\Admin\RemoteInboxNotifications\TransformerInterface; -use stdClass; +use Automattic\WooCommerce\Admin\DeprecatedClassFacade; /** * Prepare site URL for comparison. * * @package Automattic\WooCommerce\Admin\RemoteInboxNotifications\Transformers + * + * @deprecated 8.8.0 */ -class PrepareUrl implements TransformerInterface { +class PrepareUrl extends DeprecatedClassFacade { /** - * Prepares the site URL by removing the protocol and trailing slash. - * - * @param string $value a value to transform. - * @param stdClass|null $arguments arguments. - * @param string|null $default default value. + * The name of the non-deprecated class that this facade covers. * - * @return mixed|null + * @var string */ - public function transform( $value, stdClass $arguments = null, $default = null ) { - if ( ! is_string( $value ) ) { - return $default; - } - - $url_parts = wp_parse_url( rtrim( $value, '/' ) ); - - if ( ! $url_parts ) { - return $default; - } - - if ( ! isset( $url_parts['host'] ) ) { - return $default; - } - - if ( isset( $url_parts['path'] ) ) { - return $url_parts['host'] . $url_parts['path']; - } - - return $url_parts['host']; - } + protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers\ArrayColumn'; /** - * Validate Transformer arguments. - * - * @param stdClass|null $arguments arguments to validate. + * The version that this class was deprecated in. * - * @return mixed + * @var string */ - public function validate( stdClass $arguments = null ) { - return true; - } + protected static $deprecated_in_version = '8.8.0'; } diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/WCAdminActiveForProvider.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/WCAdminActiveForProvider.php index 12076f2e9d7a..21d53b4c0c1c 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/WCAdminActiveForProvider.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/WCAdminActiveForProvider.php @@ -5,20 +5,27 @@ namespace Automattic\WooCommerce\Admin\RemoteInboxNotifications; -use Automattic\WooCommerce\Admin\WCAdminHelper; - defined( 'ABSPATH' ) || exit; +use Automattic\WooCommerce\Admin\DeprecatedClassFacade; + /** * WCAdminActiveForProvider class + * + * @deprecated 8.8.0 */ -class WCAdminActiveForProvider { +class WCAdminActiveForProvider extends DeprecatedClassFacade { + /** + * The name of the non-deprecated class that this facade covers. + * + * @var string + */ + protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\WCAdminActiveForProvider'; + /** - * Get the number of seconds that the store has been active. + * The version that this class was deprecated in. * - * @return number Number of seconds. + * @var string */ - public function get_wcadmin_active_for_in_seconds() { - return WCAdminHelper::get_wcadmin_active_for_in_seconds(); - } + protected static $deprecated_in_version = '8.8.0'; } diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/WCAdminActiveForRuleProcessor.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/WCAdminActiveForRuleProcessor.php index afb6195702cf..3694337ae26e 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/WCAdminActiveForRuleProcessor.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/WCAdminActiveForRuleProcessor.php @@ -8,72 +8,26 @@ defined( 'ABSPATH' ) || exit; +use Automattic\WooCommerce\Admin\DeprecatedClassFacade; + /** * Rule processor for publishing if wc-admin has been active for at least the * given number of seconds. + * + * @deprecated 8.8.0 */ -class WCAdminActiveForRuleProcessor implements RuleProcessorInterface { - +class WCAdminActiveForRuleProcessor extends DeprecatedClassFacade { /** - * Provides the amount of time wcadmin has been active for. + * The name of the non-deprecated class that this facade covers. * - * @var WCAdminActiveForProvider + * @var string */ - protected $wcadmin_active_for_provider; + protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\WCAdminActiveForRuleProcessor'; /** - * Constructor + * The version that this class was deprecated in. * - * @param object $wcadmin_active_for_provider Provides the amount of time wcadmin has been active for. + * @var string */ - public function __construct( $wcadmin_active_for_provider = null ) { - $this->wcadmin_active_for_provider = null === $wcadmin_active_for_provider - ? new WCAdminActiveForProvider() - : $wcadmin_active_for_provider; - } - - /** - * Performs a comparison operation against the amount of time wc-admin has - * been active for in days. - * - * @param object $rule The rule being processed. - * @param object $stored_state Stored state. - * - * @return bool The result of the operation. - */ - public function process( $rule, $stored_state ) { - $active_for_seconds = $this->wcadmin_active_for_provider->get_wcadmin_active_for_in_seconds(); - - if ( ! $active_for_seconds || ! is_numeric( $active_for_seconds ) || $active_for_seconds < 0 ) { - return false; - } - - $rule_seconds = $rule->days * DAY_IN_SECONDS; - - return ComparisonOperation::compare( - $active_for_seconds, - $rule_seconds, - $rule->operation - ); - } - - /** - * Validates the rule. - * - * @param object $rule The rule to validate. - * - * @return bool Pass/fail. - */ - public function validate( $rule ) { - // Ensure that 'days' property is set and is a valid numeric value. - if ( ! isset( $rule->days ) || ! is_numeric( $rule->days ) || $rule->days < 0 ) { - return false; - } - - if ( ! isset( $rule->operation ) ) { - return false; - } - - return true; - } + protected static $deprecated_in_version = '8.8.0'; } diff --git a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/WooCommerceAdminUpdatedRuleProcessor.php b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/WooCommerceAdminUpdatedRuleProcessor.php index 646ac2f766f5..b7097fd6b4d6 100644 --- a/plugins/woocommerce/src/Admin/RemoteInboxNotifications/WooCommerceAdminUpdatedRuleProcessor.php +++ b/plugins/woocommerce/src/Admin/RemoteInboxNotifications/WooCommerceAdminUpdatedRuleProcessor.php @@ -7,30 +7,25 @@ defined( 'ABSPATH' ) || exit; +use Automattic\WooCommerce\Admin\DeprecatedClassFacade; + /** * Rule processor for sending when WooCommerce Admin has been updated. + * + * @deprecated 8.8.0 */ -class WooCommerceAdminUpdatedRuleProcessor implements RuleProcessorInterface { +class WooCommerceAdminUpdatedRuleProcessor extends DeprecatedClassFacade { /** - * Process the rule. - * - * @param object $rule The specific rule being processed by this rule processor. - * @param object $stored_state Stored state. + * The name of the non-deprecated class that this facade covers. * - * @return bool Whether the rule passes or not. + * @var string */ - public function process( $rule, $stored_state ) { - return get_option( RemoteInboxNotificationsEngine::WCA_UPDATED_OPTION_NAME, false ); - } + protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\WooCommerceAdminUpdatedRuleProcessor'; /** - * Validates the rule. - * - * @param object $rule The rule to validate. + * The version that this class was deprecated in. * - * @return bool Pass/fail. + * @var string */ - public function validate( $rule ) { - return true; - } + protected static $deprecated_in_version = '8.8.0'; } diff --git a/plugins/woocommerce/src/Admin/RemoteSpecs/DataSourcePoller.php b/plugins/woocommerce/src/Admin/RemoteSpecs/DataSourcePoller.php new file mode 100644 index 000000000000..d341d3dc0737 --- /dev/null +++ b/plugins/woocommerce/src/Admin/RemoteSpecs/DataSourcePoller.php @@ -0,0 +1,288 @@ +data_sources = $data_sources; + $this->id = $id; + + $arg_defaults = array( + 'spec_key' => 'id', + 'transient_name' => 'woocommerce_admin_' . $id . '_specs', + 'transient_expiry' => 7 * DAY_IN_SECONDS, + ); + $this->args = wp_parse_args( $args, $arg_defaults ); + } + + /** + * Get the logger instance. + * + * @return WC_Logger + */ + protected static function get_logger() { + if ( is_null( self::$logger ) ) { + self::$logger = wc_get_logger(); + } + + return self::$logger; + } + + /** + * Returns the key identifier of spec, this can easily be overwritten. Defaults to id. + * + * @param mixed $spec a JSON parsed spec coming from the JSON feed. + * @return string|boolean + */ + protected function get_spec_key( $spec ) { + $key = $this->args['spec_key']; + if ( isset( $spec->$key ) ) { + return $spec->$key; + } + return false; + } + + /** + * Reads the data sources for specs and persists those specs. + * + * @return array list of specs. + */ + public function get_specs_from_data_sources() { + $locale = get_user_locale(); + $specs_group = get_transient( $this->args['transient_name'] ) ?? array(); + $specs = isset( $specs_group[ $locale ] ) ? $specs_group[ $locale ] : array(); + + if ( ! is_array( $specs ) || empty( $specs ) ) { + $this->read_specs_from_data_sources(); + $specs_group = get_transient( $this->args['transient_name'] ); + $specs = isset( $specs_group[ $locale ] ) ? $specs_group[ $locale ] : array(); + } + + /** + * Filter specs. + * + * @param array $specs List of specs. + * @param string $this->id Spec identifier. + * + * @since 8.8.0 + */ + $specs = apply_filters( self::FILTER_NAME_SPECS, $specs, $this->id ); + return false !== $specs ? $specs : array(); + } + + /** + * Reads the data sources for specs and persists those specs. + * + * @return bool Whether any specs were read. + */ + public function read_specs_from_data_sources() { + $specs = array(); + + /** + * Filter data sources. + * + * @param array $this->data_sources List of data sources. + * @param string $this->id Spec identifier. + * + * @since 8.8.0 + */ + $data_sources = apply_filters( self::FILTER_NAME, $this->data_sources, $this->id ); + + // Note that this merges the specs from the data sources based on the + // id - last one wins. + foreach ( $data_sources as $url ) { + $specs_from_data_source = self::read_data_source( $url ); + $this->merge_specs( $specs_from_data_source, $specs, $url ); + } + + $specs_group = get_transient( $this->args['transient_name'] ); + $specs_group = is_array( $specs_group ) ? $specs_group : array(); + $locale = get_user_locale(); + $specs_group[ $locale ] = $specs; + // Persist the specs as a transient. + $this->set_specs_transient( + $specs_group, + $this->args['transient_expiry'] + ); + return count( $specs ) !== 0; + } + + /** + * Delete the specs transient. + * + * @return bool success of failure of transient deletion. + */ + public function delete_specs_transient() { + return delete_transient( $this->args['transient_name'] ); + } + + /** + * Set the specs transient. + * + * @param array $specs The specs to set in the transient. + * @param int $expiration The expiration time for the transient. + */ + public function set_specs_transient( $specs, $expiration = 0 ) { + set_transient( + $this->args['transient_name'], + $specs, + $expiration, + ); + } + + /** + * Read a single data source and return the read specs + * + * @param string $url The URL to read the specs from. + * + * @return array The specs that have been read from the data source. + */ + protected static function read_data_source( $url ) { + $logger_context = array( 'source' => $url ); + $logger = self::get_logger(); + $response = wp_remote_get( + add_query_arg( + 'locale', + get_user_locale(), + $url + ), + array( + 'user-agent' => 'WooCommerce/' . WC_VERSION . '; ' . home_url( '/' ), + ) + ); + + if ( is_wp_error( $response ) || ! isset( $response['body'] ) ) { + $logger->error( + 'Error getting data feed', + $logger_context + ); + // phpcs:ignore + $logger->error( print_r( $response, true ), $logger_context ); + + return array(); + } + + $body = $response['body']; + $specs = json_decode( $body ); + + if ( null === $specs ) { + $logger->error( + 'Empty response in data feed', + $logger_context + ); + + return array(); + } + + if ( ! is_array( $specs ) ) { + $logger->error( + 'Data feed is not an array', + $logger_context + ); + + return array(); + } + + return $specs; + } + + /** + * Merge the specs. + * + * @param Array $specs_to_merge_in The specs to merge in to $specs. + * @param Array $specs The list of specs being merged into. + * @param string $url The url of the feed being merged in (for error reporting). + */ + protected function merge_specs( $specs_to_merge_in, &$specs, $url ) { + foreach ( $specs_to_merge_in as $spec ) { + if ( ! $this->validate_spec( $spec, $url ) ) { + continue; + } + + $id = $this->get_spec_key( $spec ); + $specs[ $id ] = $spec; + } + } + + /** + * Validate the spec. + * + * @param object $spec The spec to validate. + * @param string $url The url of the feed that provided the spec. + * + * @return bool The result of the validation. + */ + protected function validate_spec( $spec, $url ) { + $logger = self::get_logger(); + $logger_context = array( 'source' => $url ); + + if ( ! $this->get_spec_key( $spec ) ) { + $logger->error( + 'Spec is invalid because the id is missing in feed', + $logger_context + ); + // phpcs:ignore + $logger->error( print_r( $spec, true ), $logger_context ); + + return false; + } + + return true; + } +} diff --git a/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/BaseLocationCountryRuleProcessor.php b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/BaseLocationCountryRuleProcessor.php new file mode 100644 index 000000000000..6db0017a7df3 --- /dev/null +++ b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/BaseLocationCountryRuleProcessor.php @@ -0,0 +1,70 @@ +value, + $rule->operation + ); + } + + /** + * Validates the rule. + * + * @param object $rule The rule to validate. + * + * @return bool Pass/fail. + */ + public function validate( $rule ) { + if ( ! isset( $rule->value ) ) { + return false; + } + + if ( ! isset( $rule->operation ) ) { + return false; + } + + return true; + } +} diff --git a/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/BaseLocationStateRuleProcessor.php b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/BaseLocationStateRuleProcessor.php new file mode 100644 index 000000000000..2e6a605091e9 --- /dev/null +++ b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/BaseLocationStateRuleProcessor.php @@ -0,0 +1,55 @@ +value, + $rule->operation + ); + } + + /** + * Validates the rule. + * + * @param object $rule The rule to validate. + * + * @return bool Pass/fail. + */ + public function validate( $rule ) { + if ( ! isset( $rule->value ) ) { + return false; + } + + if ( ! isset( $rule->operation ) ) { + return false; + } + + return true; + } +} diff --git a/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/ComparisonOperation.php b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/ComparisonOperation.php new file mode 100644 index 000000000000..3e642b1cbf02 --- /dev/null +++ b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/ComparisonOperation.php @@ -0,0 +1,76 @@ +': + return $left_operand > $right_operand; + case '>=': + return $left_operand >= $right_operand; + case '!=': + return $left_operand !== $right_operand; + case 'contains': + if ( is_array( $left_operand ) && is_string( $right_operand ) ) { + return in_array( $right_operand, $left_operand, true ); + } + if ( is_string( $right_operand ) && is_string( $left_operand ) ) { + return strpos( $right_operand, $left_operand ) !== false; + } + break; + case '!contains': + if ( is_array( $left_operand ) && is_string( $right_operand ) ) { + return ! in_array( $right_operand, $left_operand, true ); + } + if ( is_string( $right_operand ) && is_string( $left_operand ) ) { + return strpos( $right_operand, $left_operand ) === false; + } + break; + case 'in': + if ( is_array( $right_operand ) && is_string( $left_operand ) ) { + return in_array( $left_operand, $right_operand, true ); + } + if ( is_string( $left_operand ) && is_string( $right_operand ) ) { + return strpos( $left_operand, $right_operand ) !== false; + } + break; + case '!in': + if ( is_array( $right_operand ) && is_string( $left_operand ) ) { + return ! in_array( $left_operand, $right_operand, true ); + } + if ( is_string( $left_operand ) && is_string( $right_operand ) ) { + return strpos( $left_operand, $right_operand ) === false; + } + break; + case 'range': + if ( ! is_array( $right_operand ) || count( $right_operand ) !== 2 ) { + return false; + } + return $left_operand >= $right_operand[0] && $left_operand <= $right_operand[1]; + } + + return false; + } +} diff --git a/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/EvaluateAndGetStatus.php b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/EvaluateAndGetStatus.php new file mode 100644 index 000000000000..9d7920d63f18 --- /dev/null +++ b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/EvaluateAndGetStatus.php @@ -0,0 +1,59 @@ +rules ) ) { + return $current_status; + } + + $evaluated_result = $rule_evaluator->evaluate( + $spec->rules, + $stored_state, + array( + 'slug' => $spec->slug, + 'source' => 'remote-inbox-notifications', + ) + ); + + // Pending notes should be the spec status if the spec passes, + // left alone otherwise. + if ( Note::E_WC_ADMIN_NOTE_PENDING === $current_status ) { + return $evaluated_result + ? $spec->status + : Note::E_WC_ADMIN_NOTE_PENDING; + } + + // When allow_redisplay isn't set, just leave the note alone. + if ( ! isset( $spec->allow_redisplay ) || ! $spec->allow_redisplay ) { + return $current_status; + } + + // allow_redisplay is set, unaction the note if eval to true. + return $evaluated_result + ? Note::E_WC_ADMIN_NOTE_UNACTIONED + : $current_status; + } +} diff --git a/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/EvaluationLogger.php b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/EvaluationLogger.php new file mode 100644 index 000000000000..e2cf71eee5da --- /dev/null +++ b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/EvaluationLogger.php @@ -0,0 +1,90 @@ +slug = $slug; + if ( null === $logger ) { + $logger = wc_get_logger(); + } + + if ( $source ) { + $this->source = $source; + } + + $this->logger = $logger; + } + + /** + * Add evaluation result of a rule. + * + * @param string $rule_type name of the rule being tested. + * @param boolean $result result of a given rule. + */ + public function add_result( $rule_type, $result ) { + array_push( + $this->results, + array( + 'rule' => $rule_type, + 'result' => $result ? 'passed' : 'failed', + ) + ); + } + + /** + * Log the results. + */ + public function log() { + if ( false === defined( 'WC_ADMIN_DEBUG_RULE_EVALUATOR' ) || true !== constant( 'WC_ADMIN_DEBUG_RULE_EVALUATOR' ) ) { + return; + } + + foreach ( $this->results as $result ) { + $this->logger->debug( + "[{$this->slug}] {$result['rule']}: {$result['result']}", + array( 'source' => $this->source ) + ); + } + } +} diff --git a/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/FailRuleProcessor.php b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/FailRuleProcessor.php new file mode 100644 index 000000000000..96bc38fb1224 --- /dev/null +++ b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/FailRuleProcessor.php @@ -0,0 +1,36 @@ +value; + } + + return (bool) wc_calypso_bridge_is_ecommerce_plan() === $rule->value; + } + + /** + * Validate the rule. + * + * @param object $rule The rule to validate. + * + * @return bool Pass/fail. + */ + public function validate( $rule ) { + if ( ! isset( $rule->value ) ) { + return false; + } + + return true; + } +} diff --git a/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/IsWooExpressRuleProcessor.php b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/IsWooExpressRuleProcessor.php new file mode 100644 index 000000000000..b09a83791eea --- /dev/null +++ b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/IsWooExpressRuleProcessor.php @@ -0,0 +1,69 @@ +value; + } + + // If the plan is undefined, only check if it's a Woo Express plan. + if ( ! isset( $rule->plan ) ) { + return wc_calypso_bridge_is_woo_express_plan() === $rule->value; + } + + // If a plan name is defined, only evaluate the plan if we're on the Woo Express plan. + if ( wc_calypso_bridge_is_woo_express_plan() ) { + $fn = 'wc_calypso_bridge_is_woo_express_' . (string) $rule->plan . '_plan'; + if ( function_exists( $fn ) ) { + return $fn() === $rule->value; + } + + // If an invalid plan name is given, only evaluate the rule if we're targeting all plans other than the specified (invalid) one. + return false === $rule->value; + } + + return false; + } + + /** + * Validate the rule. + * + * @param object $rule The rule to validate. + * + * @return bool Pass/fail. + */ + public function validate( $rule ) { + if ( ! isset( $rule->value ) ) { + return false; + } + + if ( isset( $rule->plan ) ) { + if ( ! function_exists( 'wc_calypso_bridge_is_woo_express_plan' ) ) { + return false; + } + } + + return true; + } +} diff --git a/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/NotRuleProcessor.php b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/NotRuleProcessor.php new file mode 100644 index 000000000000..bc086a88da23 --- /dev/null +++ b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/NotRuleProcessor.php @@ -0,0 +1,64 @@ +rule_evaluator = null === $rule_evaluator + ? new RuleEvaluator() + : $rule_evaluator; + } + + /** + * Evaluates the rules in the operand and negates the result. + * + * @param object $rule The specific rule being processed by this rule processor. + * @param object $stored_state Stored state. + * + * @return bool The result of the operation. + */ + public function process( $rule, $stored_state ) { + $evaluated_operand = $this->rule_evaluator->evaluate( + $rule->operand, + $stored_state + ); + + return ! $evaluated_operand; + } + + /** + * Validates the rule. + * + * @param object $rule The rule to validate. + * + * @return bool Pass/fail. + */ + public function validate( $rule ) { + if ( ! isset( $rule->operand ) ) { + return false; + } + + return true; + } +} diff --git a/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/NoteStatusRuleProcessor.php b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/NoteStatusRuleProcessor.php new file mode 100644 index 000000000000..f5268ead08fd --- /dev/null +++ b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/NoteStatusRuleProcessor.php @@ -0,0 +1,61 @@ +note_name ); + if ( ! $status ) { + return false; + } + + return ComparisonOperation::compare( + $status, + $rule->status, + $rule->operation + ); + } + + /** + * Validates the rule. + * + * @param object $rule The rule to validate. + * + * @return bool Pass/fail. + */ + public function validate( $rule ) { + if ( ! isset( $rule->note_name ) ) { + return false; + } + + if ( ! isset( $rule->status ) ) { + return false; + } + + if ( ! isset( $rule->operation ) ) { + return false; + } + + return true; + } +} diff --git a/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/OnboardingProfileRuleProcessor.php b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/OnboardingProfileRuleProcessor.php new file mode 100644 index 000000000000..3e5a16f71cf6 --- /dev/null +++ b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/OnboardingProfileRuleProcessor.php @@ -0,0 +1,65 @@ +index ] ) ) { + return false; + } + + return ComparisonOperation::compare( + $onboarding_profile[ $rule->index ], + $rule->value, + $rule->operation + ); + } + + /** + * Validates the rule. + * + * @param object $rule The rule to validate. + * + * @return bool Pass/fail. + */ + public function validate( $rule ) { + if ( ! isset( $rule->index ) ) { + return false; + } + + if ( ! isset( $rule->value ) ) { + return false; + } + + if ( ! isset( $rule->operation ) ) { + return false; + } + + return true; + } +} diff --git a/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/OptionRuleProcessor.php b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/OptionRuleProcessor.php new file mode 100644 index 000000000000..703fc7851f46 --- /dev/null +++ b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/OptionRuleProcessor.php @@ -0,0 +1,105 @@ +operation && strpos( $rule->operation, 'contains' ) !== false; + $value_when_default_not_provided = $is_contains ? array() : false; + $is_default_set = property_exists( $rule, 'default' ); + $default_value = $is_default_set ? $rule->default : $value_when_default_not_provided; + $option_value = $this->get_option_value( $rule, $default_value, $is_contains ); + + if ( isset( $rule->transformers ) && is_array( $rule->transformers ) ) { + $option_value = TransformerService::apply( $option_value, $rule->transformers, $is_default_set, $default_value ); + } + + return ComparisonOperation::compare( + $option_value, + $rule->value, + $rule->operation + ); + } + + /** + * Retrieves the option value and handles logging if necessary. + * + * @param object $rule The specific rule being processed. + * @param mixed $default_value The default value. + * @param bool $is_contains Indicates whether the operation is "contains". + * + * @return mixed The option value. + */ + private function get_option_value( $rule, $default_value, $is_contains ) { + $option_value = get_option( $rule->option_name, $default_value ); + $is_contains_valid = $is_contains && ( is_array( $option_value ) || ( is_string( $option_value ) && is_string( $rule->value ) ) ); + + if ( $is_contains && ! $is_contains_valid ) { + $logger = wc_get_logger(); + $logger->warning( + sprintf( + 'ComparisonOperation "%s" option value "%s" is not an array, defaulting to empty array.', + $rule->operation, + $rule->option_name + ), + array( + 'option_value' => $option_value, + 'rule' => $rule, + ) + ); + $option_value = array(); + } + + return $option_value; + } + + /** + * Validates the rule. + * + * @param object $rule The rule to validate. + * + * @return bool Pass/fail. + */ + public function validate( $rule ) { + if ( ! isset( $rule->option_name ) ) { + return false; + } + + if ( ! isset( $rule->value ) ) { + return false; + } + + if ( ! isset( $rule->operation ) ) { + return false; + } + + if ( isset( $rule->transformers ) && is_array( $rule->transformers ) ) { + foreach ( $rule->transformers as $transform_args ) { + $transformer = TransformerService::create_transformer( $transform_args->use ); + if ( ! $transformer->validate( $transform_args->arguments ) ) { + return false; + } + } + } + + return true; + } +} diff --git a/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/OrRuleProcessor.php b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/OrRuleProcessor.php new file mode 100644 index 000000000000..42a6143f7927 --- /dev/null +++ b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/OrRuleProcessor.php @@ -0,0 +1,73 @@ +rule_evaluator = null === $rule_evaluator + ? new RuleEvaluator() + : $rule_evaluator; + } + + /** + * Performs an OR operation on the rule's left and right operands. + * + * @param object $rule The specific rule being processed by this rule processor. + * @param object $stored_state Stored state. + * + * @return bool The result of the operation. + */ + public function process( $rule, $stored_state ) { + foreach ( $rule->operands as $operand ) { + $evaluated_operand = $this->rule_evaluator->evaluate( + $operand, + $stored_state + ); + + if ( $evaluated_operand ) { + return true; + } + } + + return false; + } + + /** + * Validates the rule. + * + * @param object $rule The rule to validate. + * + * @return bool Pass/fail. + */ + public function validate( $rule ) { + if ( ! isset( $rule->operands ) || ! is_array( $rule->operands ) ) { + return false; + } + + return true; + } +} diff --git a/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/OrderCountRuleProcessor.php b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/OrderCountRuleProcessor.php new file mode 100644 index 000000000000..402e3cb0d467 --- /dev/null +++ b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/OrderCountRuleProcessor.php @@ -0,0 +1,69 @@ +orders_provider = null === $orders_provider + ? new OrdersProvider() + : $orders_provider; + } + + /** + * Process the rule. + * + * @param object $rule The rule to process. + * @param object $stored_state Stored state. + * + * @return bool Whether the rule passes or not. + */ + public function process( $rule, $stored_state ) { + $count = $this->orders_provider->get_order_count(); + + return ComparisonOperation::compare( + $count, + $rule->value, + $rule->operation + ); + } + + /** + * Validates the rule. + * + * @param object $rule The rule to validate. + * + * @return bool Pass/fail. + */ + public function validate( $rule ) { + if ( ! isset( $rule->value ) ) { + return false; + } + + if ( ! isset( $rule->operation ) ) { + return false; + } + + return true; + } +} diff --git a/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/OrdersProvider.php b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/OrdersProvider.php new file mode 100644 index 000000000000..f07965a06df5 --- /dev/null +++ b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/OrdersProvider.php @@ -0,0 +1,36 @@ +allowed_statuses ); + $orders_count = array_sum( $status_counts ); + + return $orders_count; + } +} diff --git a/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/PassRuleProcessor.php b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/PassRuleProcessor.php new file mode 100644 index 000000000000..86afa68a3e1a --- /dev/null +++ b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/PassRuleProcessor.php @@ -0,0 +1,37 @@ +plugins_provider = null === $plugins_provider + ? new PluginsProvider() + : $plugins_provider; + } + + /** + * Process the rule. + * + * @param object $rule The specific rule being processed by this rule processor. + * @param object $stored_state Stored state. + * + * @return bool Whether the rule passes or not. + */ + public function process( $rule, $stored_state ) { + $active_plugin_slugs = $this->plugins_provider->get_active_plugin_slugs(); + + if ( ! in_array( $rule->plugin, $active_plugin_slugs, true ) ) { + return false; + } + + $plugin_data = $this->plugins_provider->get_plugin_data( $rule->plugin ); + + if ( ! is_array( $plugin_data ) || ! array_key_exists( 'Version', $plugin_data ) ) { + return false; + } + + $plugin_version = $plugin_data['Version']; + + return version_compare( $plugin_version, $rule->version, $rule->operator ); + } + + /** + * Validates the rule. + * + * @param object $rule The rule to validate. + * + * @return bool Pass/fail. + */ + public function validate( $rule ) { + if ( ! isset( $rule->plugin ) ) { + return false; + } + + if ( ! isset( $rule->version ) ) { + return false; + } + + if ( ! isset( $rule->operator ) ) { + return false; + } + + return true; + } +} diff --git a/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/PluginsActivatedRuleProcessor.php b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/PluginsActivatedRuleProcessor.php new file mode 100644 index 000000000000..8b0b25ee5723 --- /dev/null +++ b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/PluginsActivatedRuleProcessor.php @@ -0,0 +1,81 @@ +plugins_provider = null === $plugins_provider + ? new PluginsProvider() + : $plugins_provider; + } + + /** + * Process the rule. + * + * @param object $rule The specific rule being processed by this rule processor. + * @param object $stored_state Stored state. + * + * @return bool Whether the rule passes or not. + */ + public function process( $rule, $stored_state ) { + if ( ! is_countable( $rule->plugins ) || 0 === count( $rule->plugins ) ) { + return false; + } + + $active_plugin_slugs = $this->plugins_provider->get_active_plugin_slugs(); + + foreach ( $rule->plugins as $plugin_slug ) { + if ( ! is_string( $plugin_slug ) ) { + $logger = wc_get_logger(); + $logger->warning( + __( 'Invalid plugin slug provided in the plugins activated rule.', 'woocommerce' ) + ); + return false; + } + + if ( ! in_array( $plugin_slug, $active_plugin_slugs, true ) ) { + return false; + } + } + + return true; + } + + /** + * Validates the rule. + * + * @param object $rule The rule to validate. + * + * @return bool Pass/fail. + */ + public function validate( $rule ) { + if ( ! isset( $rule->plugins ) || ! is_array( $rule->plugins ) ) { + return false; + } + + return true; + } +} diff --git a/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/ProductCountRuleProcessor.php b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/ProductCountRuleProcessor.php new file mode 100644 index 000000000000..cf61d5661c24 --- /dev/null +++ b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/ProductCountRuleProcessor.php @@ -0,0 +1,78 @@ +product_query = null === $product_query + ? new \WC_Product_Query( + array( + 'limit' => 1, + 'paginate' => true, + 'return' => 'ids', + 'status' => array( 'publish' ), + ) + ) + : $product_query; + } + + /** + * Performs a comparison operation against the number of products. + * + * @param object $rule The specific rule being processed by this rule processor. + * @param object $stored_state Stored state. + * + * @return bool The result of the operation. + */ + public function process( $rule, $stored_state ) { + $products = $this->product_query->get_products(); + + return ComparisonOperation::compare( + $products->total, + $rule->value, + $rule->operation + ); + } + + /** + * Validates the rule. + * + * @param object $rule The rule to validate. + * + * @return bool Pass/fail. + */ + public function validate( $rule ) { + if ( ! isset( $rule->value ) ) { + return false; + } + + if ( ! isset( $rule->operation ) ) { + return false; + } + + return true; + } +} diff --git a/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/PublishAfterTimeRuleProcessor.php b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/PublishAfterTimeRuleProcessor.php new file mode 100644 index 000000000000..a8878523ef3c --- /dev/null +++ b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/PublishAfterTimeRuleProcessor.php @@ -0,0 +1,67 @@ +date_time_provider = null === $date_time_provider + ? new CurrentDateTimeProvider() + : $date_time_provider; + } + + /** + * Process the rule. + * + * @param object $rule The specific rule being processed by this rule processor. + * @param object $stored_state Stored state. + * + * @return bool Whether the rule passes or not. + */ + public function process( $rule, $stored_state ) { + return $this->date_time_provider->get_now() >= new \DateTime( $rule->publish_after ); + } + + /** + * Validates the rule. + * + * @param object $rule The rule to validate. + * + * @return bool Pass/fail. + */ + public function validate( $rule ) { + if ( ! isset( $rule->publish_after ) ) { + return false; + } + + try { + new \DateTime( $rule->publish_after ); + } catch ( \Throwable $e ) { + return false; + } + + return true; + } +} diff --git a/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/PublishBeforeTimeRuleProcessor.php b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/PublishBeforeTimeRuleProcessor.php new file mode 100644 index 000000000000..2a768556e866 --- /dev/null +++ b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/PublishBeforeTimeRuleProcessor.php @@ -0,0 +1,67 @@ +date_time_provider = null === $date_time_provider + ? new CurrentDateTimeProvider() + : $date_time_provider; + } + + /** + * Process the rule. + * + * @param object $rule The specific rule being processed by this rule processor. + * @param object $stored_state Stored state. + * + * @return bool Whether the rule passes or not. + */ + public function process( $rule, $stored_state ) { + return $this->date_time_provider->get_now() <= new \DateTime( $rule->publish_before ); + } + + /** + * Validates the rule. + * + * @param object $rule The rule to validate. + * + * @return bool Pass/fail. + */ + public function validate( $rule ) { + if ( ! isset( $rule->publish_before ) ) { + return false; + } + + try { + new \DateTime( $rule->publish_before ); + } catch ( \Throwable $e ) { + return false; + } + + return true; + } +} diff --git a/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/README.md b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/README.md new file mode 100644 index 000000000000..12292fc7f6c6 --- /dev/null +++ b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/README.md @@ -0,0 +1,479 @@ +# Rule + +Rules in an array are executed as an AND operation. If there are no rules in the array the result is false and the specified notification is not shown. + +## Operations + +Some rule types support an `operation` value, which is used to compare two +values. The following operations are implemented: + +- `=` +- `<` +- `<=` +- `>` +- `>=` +- `!=` +- `contains` +- `!contains` +- `in` (Added in WooCommerce 8.2.0) +- `!in` (Added in WooCommerce 8.2.0) +- `range` (Added in WooCommerce 8.8.0) + +### contains and !contains + +`contains` and `!contains` allow checking if the provided value is present (or +not present) in the haystack value. An example of this is using the +`onboarding_profile` rule to match on a value in the `product_types` array - +this rule matches if `physical` was selected as a product type in the +onboarding profile: + +```json +{ + "type": "onboarding_profile", + "index": "product_types", + "operation": "contains", + "value": "physical" +} +``` + +### in and !in + +`in` and `!in` allow checking if a value is found (or not found) in a provided array. For example, using the `in` comparison operator to check if the base country location value is found in a given array, as below. This rule matches if the `base_location_country` is `US`, `NZ`, or `ZA`. **NOTE:** These comparisons were added in **WooCommerce 8.2.0**. If the spec is read by an older version of WooCommerce, the rule will evaluate to `false`. + +```json +{ + "type": "base_location_country", + "value": [ + "US", + "NZ", + "ZA" + ], + "operation": "in" +} +``` + +### range + +`range` operator performs an inclusive check to determine if a number falls within a certain range. +This means that both the 'from' and 'to' values of the specified range are included in the check. + +The following rule returns true when `woocommerce_remote_variant_assignment` value is between 1 and 10. + +```json +{ + "type": "option", + "value": [ 1, 10 ], + "default": 0, + "operation": "range", + "option_name": "woocommerce_remote_variant_assignment", +} +``` + +## Plugins activated + +This passes if all of the listed plugins are installed and activated. + +`plugins` is required. + +```json +{ + "type": "plugins_activated", + "plugins": [ + "plugin-slug-1', + "plugin-slug-2" + ] +} +``` + +## Publish after time + +This passes if the system time is after the specified date/time. + +Note that using both `publish_after_time` and `publish_before_time` allows timeboxing a note which could be useful for promoting a sale. + +`publish_after` is required. + +```json +{ + "type": "publish_after_time", + "publish_after": "2020-04-22 00:00:00" +} +``` + +## Publish before time + +This passes if the system time is before the specified date/time. + +Note that using both `publish_after_time` and `publish_before_time` allows timeboxing a note which could be useful for promoting a sale. + +`publish_before` is required. + +```json +{ + "type": "publish_before_time", + "publish_before": "2020-04-22 00:00:00" +} +``` + +## Not + +This negates the rules in the provided set of rules. Note that the rules in `operand` get ANDed together into a single boolean. + +`operand` is required. + +```json +{ + "type": "not", + "operand": [ + , + ... + ] +} +``` + +## Or + +This performs an OR operation on the operands, passing if any of the operands evaluates to true. Note that if the operands are an array of `Rule`s (as in the first example), each operand is treated as an AND operation. + +`operands` is required. + +```json +{ + "type": "or", + "operands": [ + [ + , + ... + ], + [ + , + ... + ] + ] +} +``` + +Alternatively: + +```json +{ + "type": "or", + "operands": [ + , + ... + ] +} +``` + +## Fail + +This just returns a false value. This is useful if you want to keep a specification around, but don't want it displayed. + +```json +{ + "type": "fail" +} +``` + +## Plugin version + +This compares the installed version of the plugin to the required version, using the comparison operator. If the plugin isn’t activated this returns false. + +`plugin`, `version`, and `operator` are required. + +This example passes if Jetpack 8.4.1 is installed and activated. + +```json +{ + "type": "plugin_version", + "plugin": "jetpack", + "version": "8.4.1", + "operator": "=" +} +``` + +## Stored state + +This allows access to a stored state containing calculated values that otherwise would be impossible to reproduce using other rules. It performs the comparison operation against the stored state value. + +This example passes if the `there_were_no_products` index is equal to `true`. + +```json +{ + "type": "stored_state", + "index": "there_were_no_products", + "operation": "=", + "value": true +} +``` + +There are only a limited amount of indices available to this rule, and new indices will need a new version of the WC Admin plugin to be installed. + +The currently available indices are: + +```json +there_were_no_products +there_are_now_products +new_product_count +``` + +`index`, `operation`, and `value` are required. + +## Product count + +This passes if the number of products currently in the system match the comparison operation. + +This example passes if there are more than 10 products currently in the system. + +```json +{ + "type": "product_count", + "operation": ">", + "value": 10 +} +``` + +`operation` and `value` are required. + +## Order count + +This passes if the number of orders currently in the system match the comparison operation. + +This example passes if there are more than 10 orders currently in the system. + +```json +{ + "type": "order_count", + "operation": ">", + "value": 10 +} +``` + +`operation` and `value` are required. + +## WooCommerce Admin active for + +This passes if the time WooCommerce Admin has been active for (in days) matches the comparison operation. + +This is used as a proxy indicator of the age of the shop. + +This example passes if it has been active for more than 8 days. + +```json +{ + "type": "wcadmin_active_for", + "operation": ">", + "days": 8 +} +``` + +`operation` and `days` are required. + +## Onboarding profile + +This allows access to the onboarding profile that was built up in the onboarding wizard. The below example passes when the current revenue selected was "none". + +```json +{ + "type": "onboarding_profile", + "index": "revenue", + "operation": "=", + "value": "none" +} +``` + +`index`, `operation`, and `value` are all required. + +## Is eCommerce + +This passes when the store is on a WordPress.com site with the eCommerce plan. + +```json +{ + "type": "is_ecommerce", + "value": true +} +``` + +`value` is required. + +## Is Woo Express + +This passes when the store is on a WordPress.com site with a Woo Express plan active. +You can optionally pass the `plan` name to target a specific Woo Express plan, e.g. `performance`. + +```json +{ + "type": "is_woo_express", + "plan": "trial|essential|performance", + "value": true +} +``` + +`value` is required. +`plan` is optional, e.g. `trial`, `essential`, `performance`. + +## Base location - country + +This passes when the store is located in the specified country. + +```json +{ + "type": "base_location_country", + "value": "US", + "operation": "=" +} +``` + +`value` and `operation` are both required. + +## Base location - state + +This passes when the store is located in the specified state. + +```json +{ + "type": "base_location_state", + "value": "TX", + "operation": "=" +} +``` + +`value` and `operation` are both required. + +## Note status + +This passes when the status of the specified note matches the specified status. +The below example passes when the `wc-admin-mobile-app` note has not been +actioned. + +```json +{ + "type": "note_status", + "note_name": "wc-admin-mobile-app", + "status": "actioned", + "operation": "!=" +} +``` + +## Total Payments Value + +This passes when the total value of all payments for a given timeframe +compared to the provided value pass the operation test. + +`timeframe` can be one of `last_week`, `last_month`, `last_quarter`, `last_6_months`, `last_year` + +```json +{ + "type": "total_payments_value", + "timeframe": "last_month", + "value": 2300, + "operation": ">" +} +``` + +`timeframe`, `value`, and `operation` are all required. + +## Option + +This passes when the option value matches the value using the operation. + +```json +{ + "type": "option", + "option_name": "woocommerce_currency", + "value": "USD", + "default": "USD", + "operation": "=" +} +``` + +`option_name`, `value`, and `operation` are all required. `default` is not required and allows a default value to be used if the option does not exist. + +### Option Transformer + +This transforms the given option value into a different value by a series of transformers. + +Example option value: + +```php +Array +( + [setup_client] => + [industry] => Array + ( + [0] => Array + ( + [slug] => food-drink + ) + + [1] => Array + ( + [slug] => fashion-apparel-accessories + ) + ) +) +``` + +If you want to ensure that the industry array contains `fashion-apparel-accessories`, you can use the following Option definition with transformers. + +```json +{ + "type": "option", + "transformers": [ + { + "use": "dot_notation", + "arguments": { + "path": "industry" + } + }, + { + "use": "array_column", + "arguments": { + "key": "slug" + } + }, + { + "use": "array_search", + "arguments": { + "value": "fashion-apparel-accessories" + } + } + ], + "option_name": "woocommerce_onboarding_profile", + "value": "fashion-apparel-accessories", + "default": "USD", + "operation": "=" +} +``` + +You can find a list of transformers and examples in the transformer [README](./Transformers/README.md). + +## WCA updated + +This passes when WooCommerce Admin has just been updated. The specs will be run +on update. Note that this doesn't provide a way to check the version number as +the `plugin_version` rule can be used to check for a specific version of the +WooCommerce Admin plugin. + +```json +{ + type: "wca_updated" +} +``` + +No other values are needed. + +## Debugging Specification + +You can see the evaluation of each specification by turning on an optional evaluation logger. + +1. Define `WC_ADMIN_DEBUG_RULE_EVALUATOR` constant in `wp-config.php`. `define('WC_ADMIN_DEBUG_RULE_EVALUATOR', true);` +2. Run `wc_admin_daily` +3. cd to `wp-content/uploads/wc-logs/` and check a log file in `remote-inbox-notifications-:date-hash.log` format. + +You can tail the log file with a slug name to see the evaluation of a rule that you are testing. + +Example: + +`tail -f remote-inbox-notifications-2021-06-15-128.log | grep 'wcpay-promo-2021-6-incentive-2'` diff --git a/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/RuleEvaluator.php b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/RuleEvaluator.php new file mode 100644 index 000000000000..a4f3977d9b8e --- /dev/null +++ b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/RuleEvaluator.php @@ -0,0 +1,92 @@ +get_rule_processor = null === $get_rule_processor + ? new GetRuleProcessor() + : $get_rule_processor; + } + + /** + * Evaluate the given rules as an AND operation - return false early if a + * rule evaluates to false. + * + * @param array|object $rules The rule or rules being processed. + * @param object|null $stored_state Stored state. + * @param array $logger_args Arguments for the event logger. `slug` is required. + * + * @throws \InvalidArgumentException Thrown when $logger_args is missing slug. + * + * @return bool The result of the operation. + */ + public function evaluate( $rules, $stored_state = null, $logger_args = array() ) { + + if ( is_bool( $rules ) ) { + return $rules; + } + + if ( ! is_array( $rules ) ) { + $rules = array( $rules ); + } + + if ( 0 === count( $rules ) ) { + return false; + } + + $evaluation_logger = null; + + if ( count( $logger_args ) ) { + if ( ! array_key_exists( 'slug', $logger_args ) ) { + throw new \InvalidArgumentException( 'Missing required field: slug in $logger_args.' ); + } + + array_key_exists( 'source', $logger_args ) ? $source = $logger_args['source'] : $source = null; + + $evaluation_logger = new EvaluationLogger( $logger_args['slug'], $source ); + } + + foreach ( $rules as $rule ) { + if ( ! is_object( $rule ) ) { + return false; + } + + $processor = $this->get_rule_processor->get_processor( $rule->type ); + $processor_result = $processor->process( $rule, $stored_state ); + $evaluation_logger && $evaluation_logger->add_result( $rule->type, $processor_result ); + + if ( ! $processor_result ) { + $evaluation_logger && $evaluation_logger->log(); + return false; + } + } + + $evaluation_logger && $evaluation_logger->log(); + + return true; + } +} diff --git a/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/RuleProcessorInterface.php b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/RuleProcessorInterface.php new file mode 100644 index 000000000000..0c1e20a1a8d3 --- /dev/null +++ b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/RuleProcessorInterface.php @@ -0,0 +1,32 @@ +{$rule->index} ) ) { + return false; + } + + return ComparisonOperation::compare( + $stored_state->{$rule->index}, + $rule->value, + $rule->operation + ); + } + + /** + * Validates the rule. + * + * @param object $rule The rule to validate. + * + * @return bool Pass/fail. + */ + public function validate( $rule ) { + if ( ! isset( $rule->index ) ) { + return false; + } + + if ( ! isset( $rule->value ) ) { + return false; + } + + if ( ! isset( $rule->operation ) ) { + return false; + } + + return true; + } +} diff --git a/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/StoredStateSetupForProducts.php b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/StoredStateSetupForProducts.php new file mode 100644 index 000000000000..bde76df21e90 --- /dev/null +++ b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/StoredStateSetupForProducts.php @@ -0,0 +1,132 @@ +there_were_no_products = ! self::are_there_products(); + $stored_state->there_are_now_products = ! $stored_state->there_were_no_products; + + return $stored_state; + } + + /** + * Are there products query. + * + * @return bool + */ + private static function are_there_products() { + $query = new \WC_Product_Query( + array( + 'limit' => 1, + 'paginate' => true, + 'return' => 'ids', + 'status' => array( 'publish' ), + ) + ); + $products = $query->get_products(); + $count = $products->total; + + return $count > 0; + } + + /** + * Runs on product importer steps. + */ + public static function run_on_product_importer() { + // We're only interested in when the importer completes. + // phpcs:disable WordPress.Security.NonceVerification.Recommended + if ( ! isset( $_REQUEST['step'] ) ) { + return; + } + if ( 'done' !== $_REQUEST['step'] ) { + return; + } + // phpcs:enable + + self::update_stored_state_and_possibly_run_remote_notifications(); + } + + /** + * Runs when a post status transitions, but we're only interested if it is + * a product being published. + * + * @param string $new_status The new status. + * @param string $old_status The old status. + * @param Post $post The post. + */ + public static function run_on_transition_post_status( $new_status, $old_status, $post ) { + if ( + 'product' !== $post->post_type || + 'publish' !== $new_status + ) { + return; + } + + self::update_stored_state_and_possibly_run_remote_notifications(); + } + + /** + * Enqueues an async action (using action-scheduler) to run remote + * notifications. + */ + private static function update_stored_state_and_possibly_run_remote_notifications() { + $stored_state = RemoteInboxNotificationsEngine::get_stored_state(); + // If the stored_state is the same, we don't need to run remote notifications to avoid unnecessary action scheduling. + if ( true === $stored_state->there_are_now_products ) { + return; + } + + $stored_state->there_are_now_products = true; + RemoteInboxNotificationsEngine::update_stored_state( $stored_state ); + + // Run self::run_remote_notifications asynchronously. + as_enqueue_async_action( self::ASYNC_RUN_REMOTE_NOTIFICATIONS_ACTION_NAME ); + } +} diff --git a/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/TotalPaymentsVolumeProcessor.php b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/TotalPaymentsVolumeProcessor.php new file mode 100644 index 000000000000..9530719dd9b2 --- /dev/null +++ b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/TotalPaymentsVolumeProcessor.php @@ -0,0 +1,93 @@ +timeframe ); + $reports_revenue = $this->get_reports_query( + array( + 'before' => $dates['end'], + 'after' => $dates['start'], + 'interval' => 'year', + 'fields' => array( 'total_sales' ), + ) + ); + $report_data = $reports_revenue->get_data(); + + if ( ! $report_data || ! isset( $report_data->totals->total_sales ) ) { + return false; + } + + $value = $report_data->totals->total_sales; + + return ComparisonOperation::compare( + $value, + $rule->value, + $rule->operation + ); + } + + /** + * Validates the rule. + * + * @param object $rule The rule to validate. + * + * @return bool Pass/fail. + */ + public function validate( $rule ) { + $allowed_timeframes = array( + 'last_week', + 'last_month', + 'last_quarter', + 'last_6_months', + 'last_year', + ); + + if ( ! isset( $rule->timeframe ) || ! in_array( $rule->timeframe, $allowed_timeframes, true ) ) { + return false; + } + + if ( ! isset( $rule->value ) || ! is_numeric( $rule->value ) ) { + return false; + } + + if ( ! isset( $rule->operation ) ) { + return false; + } + + return true; + } + + /** + * Get the report query. + * + * @param array $args The query args. + * + * @return RevenueQuery The report query. + */ + protected function get_reports_query( $args ) { + return new RevenueQuery( + $args + ); + } +} diff --git a/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/Transformers/ArrayColumn.php b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/Transformers/ArrayColumn.php new file mode 100644 index 000000000000..7d342bb7c29d --- /dev/null +++ b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/Transformers/ArrayColumn.php @@ -0,0 +1,56 @@ +key ); + } + + /** + * Validate Transformer arguments. + * + * @param stdClass|null $arguments arguments to validate. + * + * @return mixed + */ + public function validate( stdClass $arguments = null ) { + if ( ! isset( $arguments->key ) ) { + return false; + } + + if ( + null !== $arguments->key && + ! is_string( $arguments->key ) && + ! is_int( $arguments->key ) + ) { + return false; + } + + return true; + } +} diff --git a/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/Transformers/ArrayFlatten.php b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/Transformers/ArrayFlatten.php new file mode 100644 index 000000000000..288754a77d40 --- /dev/null +++ b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/Transformers/ArrayFlatten.php @@ -0,0 +1,49 @@ +value, $value, true ); + if ( false !== $key ) { + return $value[ $key ]; + } + + return null; + } + + /** + * Validate Transformer arguments. + * + * @param stdClass|null $arguments arguments to validate. + * + * @return mixed + */ + public function validate( stdClass $arguments = null ) { + if ( ! isset( $arguments->value ) ) { + return false; + } + + return true; + } +} diff --git a/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/Transformers/ArrayValues.php b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/Transformers/ArrayValues.php new file mode 100644 index 000000000000..e866bfc34afe --- /dev/null +++ b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/Transformers/ArrayValues.php @@ -0,0 +1,41 @@ +get( $value, $arguments->path, $default_value ); + } + + /** + * Find the given $path in $array_to_search by dot notation. + * + * @param array $array_to_search an array to search in. + * @param string $path a path in the given array. + * @param null $default_value default value to return if $path was not found. + * + * @return mixed|null + */ + public function get( $array_to_search, $path, $default_value = null ) { + if ( ! is_array( $array_to_search ) ) { + return $default_value; + } + + if ( isset( $array_to_search[ $path ] ) ) { + return $array_to_search[ $path ]; + } + + foreach ( explode( '.', $path ) as $segment ) { + if ( ! is_array( $array_to_search ) || ! array_key_exists( $segment, $array_to_search ) ) { + return $default_value; + } + + $array_to_search = $array_to_search[ $segment ]; + } + + return $array_to_search; + } + + /** + * Validate Transformer arguments. + * + * @param stdClass|null $arguments arguments to validate. + * + * @return mixed + */ + public function validate( stdClass $arguments = null ) { + if ( ! isset( $arguments->path ) ) { + return false; + } + + return true; + } +} diff --git a/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/Transformers/PrepareUrl.php b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/Transformers/PrepareUrl.php new file mode 100644 index 000000000000..c4bfabcd8ed5 --- /dev/null +++ b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/Transformers/PrepareUrl.php @@ -0,0 +1,55 @@ + + +# Option Transformer + +An option transformer is a class that transforms the given option value into a different value for the comparison operation. + +Transformers run in the order in which they are defined, and each transformer passes down the value it transformed to the next transformer for consumption. + +**Definition example**: transformers are always used with `option` rule. + +```js + { + "slug": "test-note", + ... + ], + "rules": [ + { + "type": "option", + "transformers": [ + { + "use": "dot_notation", + "arguments": { + "path": "industry" + } + }, + { + "use": "array_column", + "arguments": { + "key": "slug" + } + } + ], + "option_name": "woocommerce_onboarding_profile", + "operation": "!=", + "value": "fashion-apparel-accessories", + "default": [] + } + ] + } +``` + +## array_column + +PHP's built-in `array_column` to select values from a single column. For more information about how array_column works, please see PHP's [official documentation](https://www.php.net/manual/en/function.array-column.php). + +### Arguments + +| name | description | +| ---- | -------------- | +| key | array key name | + +### Definition + +```php +"transformers": [ + { + "use": "array_column", + "arguments": { + "key": "industry" + } + } +], +``` + +### Example + +Given the following data + +```php +array( + array("industry" => "media" ), + array("industry" => "software" ) +); +``` + +Use `array_column` to extract `array("media", "software")` then choose the first element with `dot_notation`. + +```php +"transformers": [ + { + "use": "array_column", + "arguments": { + "key": "industry" + } + }, + { + "use": "dot_notation", + "arguments": { + "key": "0" + } + } +], +``` + +**Output**: "media" + + + + + +## array_flatten + +Flattens a nested array. + +### Arguments: N/A + +### Definition + +```php +"transformers": [ + { + "use": "array_flatten" + } +], +``` + +### Example + +Given the following data + +```php +array( + array( + 'member1', + ), + array( + 'member2', + ), + array( + 'member3', + ), +); +``` + +Use `array_flatten` to extract `array("member1", "member2", "member3")` then use `array_search` to make sure it has `member2` + + +```php +"transformers": [ + { + "use": "array_flatten", + }, + { + "use": "array_search", + "arguments": { + "key": "member2" + } + } +], +``` + +**Output**: true + +## array_keys + +PHP's built-in `array_keys` to return keys from an array. For more information about how `array_keys` works, please see PHP’s [official documentation](https://www.php.net/manual/en/function.array-column.php). + +### Arguments: N/A + +### Definition + +```php +"transformers": [ + { + "use": "array_keys" + } +], +``` + +### Example + +Given the following data + +```php +array( + "name" => "tester", + "address" => "test", + "supports_version_2" => true +) +``` + +Use `array_keys` to extract `array("name", "address", "supports_version_2")` and then use `array_search` to make sure it has `supports_version_2` + +```php +"transformers": [ + { + "use": "array_keys", + }, + { + "use": "array_search", + "arguments": { + "key": "member2" + } + } +], +``` + +**Output**: true + +## array_search + +PHP's built-in `array_search` to search a value in an array. For more information about how `array_search` works, please see PHP’s [official documentation](https://www.php.net/manual/en/function.array-search.php). + +### Arguments + +|name|description| +|----|---------| +| value | a value to search in the given array | + +### Definition + +```php +"transformers": [ + { + "use": "array_search", + "arguments": { + "value": "test" + } + } +], +``` + +### Examples + +See examples from [array_flatten](#array_flatten) and [array_keys](#array_keys) + +## array_values + +PHP's built-in array_values to return values from an array. For more information about how `array_values` works, please see PHP’s [official documentation](https://www.php.net/manual/en/function.array-values). + + +### Arguments: N/A + +### Definition + +```php +"transformers": [ + { + "use": "array_values" + } +], +``` + +### Example + +Given the following data + +```php +array ( + "size" => "x-large" +) +``` + +Use `array_values` to extract `array("x-large")` + +```php +"transformers": [ + { + "use": "array_values", + } +], +``` + +**Output:** "x-large" + + +## dot_notation + +Uses dot notation to select a value in an array. Dot notation lets you access an array as if it is an object. + +### Arguments: N/A + +### Definition + + +```php +"transformers": [ + { + "use": "dot_notation", + "arguments": { + "path": "name" + } + } +], +``` + +### Example + + + +Given the following data + +```php +array( + 'name' => 'john', + 'members' => ['member1', 'member2'] +); +``` + +Select `name` field. + +```php +"transformers": [ + { + "use": "dot_notation", + "arguments": { + "path": "name" + } + } +], +``` + +**Output:** "john" + +Select `member2`. You can access array items with an index. + +```php +"transformers": [ + { + "use": "dot_notation", + "arguments": { + "path": "members.1" + } + } +], +``` + +**Output:**: "member2" + +## count + +PHP's built-in count to return the number of values from a countable, such as an array. + +### Arguments: N/A + +### Definition + +```php +"transformers": [ + { + "use": "count" + } +], +``` + +### Example + +Given the following list of usernames + +```php +array( + "username1", + "username2", + "username3" +) +``` + +Let's count # of users with `count` + +```php +"transformers": [ + { + "use": "count", + } +], +``` + +**Output:** 3 + +## prepare_url + +This prepares the site URL by removing the protocol and the last slash. + +### Arguments: N/A + +### Definition + +```php +"transformers": [ + { + "use": "prepare_url" + } +], +``` + +### Example + +Given the following data + +```php +$siteurl = "https://mysite.com/" +``` + +Removes the protocol and the last slash. + +```php +"transformers": [ + { + "use": "prepare_url", + } +], +``` + +**Output:** "mysite.com" diff --git a/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/Transformers/TransformerInterface.php b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/Transformers/TransformerInterface.php new file mode 100644 index 000000000000..332556f301d9 --- /dev/null +++ b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/Transformers/TransformerInterface.php @@ -0,0 +1,34 @@ +use ) ) { + throw new InvalidArgumentException( 'Missing required config value: use' ); + } + + if ( ! isset( $transformer_config->arguments ) ) { + $transformer_config->arguments = null; + } + + $transformer = self::create_transformer( $transformer_config->use ); + if ( null === $transformer ) { + throw new InvalidArgumentException( "Unable to find a transformer by name: {$transformer_config->use}" ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped + } + + $target_value = $transformer->transform( $target_value, $transformer_config->arguments, $is_default_set ? $default_value : null ); + + // Break early when there's no more value to traverse. + if ( null === $target_value ) { + break; + } + } + + if ( $is_default_set ) { + // Nulls always return the default value. + if ( null === $target_value ) { + return $default_value; + } + + // When type of the default value is different from the target value, return the default value + // to ensure type safety. + if ( gettype( $default_value ) !== gettype( $target_value ) ) { + return $default_value; + } + } + + return $target_value; + } +} diff --git a/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/WCAdminActiveForProvider.php b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/WCAdminActiveForProvider.php new file mode 100644 index 000000000000..c6f25eb6cf8a --- /dev/null +++ b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/WCAdminActiveForProvider.php @@ -0,0 +1,24 @@ +wcadmin_active_for_provider = null === $wcadmin_active_for_provider + ? new WCAdminActiveForProvider() + : $wcadmin_active_for_provider; + } + + /** + * Performs a comparison operation against the amount of time wc-admin has + * been active for in days. + * + * @param object $rule The rule being processed. + * @param object $stored_state Stored state. + * + * @return bool The result of the operation. + */ + public function process( $rule, $stored_state ) { + $active_for_seconds = $this->wcadmin_active_for_provider->get_wcadmin_active_for_in_seconds(); + + if ( ! $active_for_seconds || ! is_numeric( $active_for_seconds ) || $active_for_seconds < 0 ) { + return false; + } + + $rule_seconds = $rule->days * DAY_IN_SECONDS; + + return ComparisonOperation::compare( + $active_for_seconds, + $rule_seconds, + $rule->operation + ); + } + + /** + * Validates the rule. + * + * @param object $rule The rule to validate. + * + * @return bool Pass/fail. + */ + public function validate( $rule ) { + // Ensure that 'days' property is set and is a valid numeric value. + if ( ! isset( $rule->days ) || ! is_numeric( $rule->days ) || $rule->days < 0 ) { + return false; + } + + if ( ! isset( $rule->operation ) ) { + return false; + } + + return true; + } +} diff --git a/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/WooCommerceAdminUpdatedRuleProcessor.php b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/WooCommerceAdminUpdatedRuleProcessor.php new file mode 100644 index 000000000000..46eb5c9d444e --- /dev/null +++ b/plugins/woocommerce/src/Admin/RemoteSpecs/RuleProcessors/WooCommerceAdminUpdatedRuleProcessor.php @@ -0,0 +1,38 @@ +possibly_refresh_data_source_pollers(); if ( $this->is_remote_inbox_notifications_enabled() ) { - DataSourcePoller::get_instance()->read_specs_from_data_sources(); + RemoteInboxNotificationsDataSourcePoller::get_instance()->read_specs_from_data_sources(); RemoteInboxNotificationsEngine::run(); } diff --git a/plugins/woocommerce/src/Internal/Admin/RemoteFreeExtensions/EvaluateExtension.php b/plugins/woocommerce/src/Internal/Admin/RemoteFreeExtensions/EvaluateExtension.php index a51c3e3307e6..bf80b7a40bd5 100644 --- a/plugins/woocommerce/src/Internal/Admin/RemoteFreeExtensions/EvaluateExtension.php +++ b/plugins/woocommerce/src/Internal/Admin/RemoteFreeExtensions/EvaluateExtension.php @@ -8,7 +8,7 @@ defined( 'ABSPATH' ) || exit; use Automattic\WooCommerce\Admin\PluginsHelper; -use Automattic\WooCommerce\Admin\RemoteInboxNotifications\RuleEvaluator; +use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\RuleEvaluator; /** * Evaluates the extension and returns it. diff --git a/plugins/woocommerce/src/Internal/Admin/RemoteFreeExtensions/RemoteFreeExtensionsDataSourcePoller.php b/plugins/woocommerce/src/Internal/Admin/RemoteFreeExtensions/RemoteFreeExtensionsDataSourcePoller.php index 602981f75898..073380ac218e 100644 --- a/plugins/woocommerce/src/Internal/Admin/RemoteFreeExtensions/RemoteFreeExtensionsDataSourcePoller.php +++ b/plugins/woocommerce/src/Internal/Admin/RemoteFreeExtensions/RemoteFreeExtensionsDataSourcePoller.php @@ -2,10 +2,11 @@ namespace Automattic\WooCommerce\Internal\Admin\RemoteFreeExtensions; +use Automattic\WooCommerce\Admin\RemoteSpecs\DataSourcePoller; /** * Specs data source poller class for remote free extensions. */ -class RemoteFreeExtensionsDataSourcePoller extends \Automattic\WooCommerce\Admin\DataSourcePoller { +class RemoteFreeExtensionsDataSourcePoller extends DataSourcePoller { const ID = 'remote_free_extensions'; diff --git a/plugins/woocommerce/src/Internal/Admin/WCPayPromotion/WCPayPromotionDataSourcePoller.php b/plugins/woocommerce/src/Internal/Admin/WCPayPromotion/WCPayPromotionDataSourcePoller.php index d7f9cbd317f4..1616e9f56b49 100644 --- a/plugins/woocommerce/src/Internal/Admin/WCPayPromotion/WCPayPromotionDataSourcePoller.php +++ b/plugins/woocommerce/src/Internal/Admin/WCPayPromotion/WCPayPromotionDataSourcePoller.php @@ -1,7 +1,7 @@ get_processor( 'unknown rule type' ); - $this->assertEquals( 'Automattic\\WooCommerce\\Admin\\RemoteInboxNotifications\\FailRuleProcessor', get_class( $result ) ); + $this->assertEquals( 'Automattic\\WooCommerce\\Admin\\RemoteSpecs\\RuleProcessors\\FailRuleProcessor', get_class( $result ) ); } } diff --git a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/is-woo-express-rule-processor.php b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/is-woo-express-rule-processor.php index 0f1f52f7ea5d..5db49ff717f6 100644 --- a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/is-woo-express-rule-processor.php +++ b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/is-woo-express-rule-processor.php @@ -5,7 +5,7 @@ * @package WooCommerce\Admin\Tests\RemoteInboxNotifications */ -use Automattic\WooCommerce\Admin\RemoteInboxNotifications\IsWooExpressRuleProcessor; +use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\IsWooExpressRuleProcessor; /** * class WC_Admin_Tests_RemoteInboxNotifications_IsWooExpressRuleProcessor diff --git a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/mock-get-rule-processor.php b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/mock-get-rule-processor.php index 2d4a0beabe66..5de623920a57 100644 --- a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/mock-get-rule-processor.php +++ b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/mock-get-rule-processor.php @@ -5,8 +5,8 @@ * @package WooCommerce\Admin\Tests\RemoteInboxNotifications */ -use Automattic\WooCommerce\Admin\RemoteInboxNotifications\PublishAfterTimeRuleProcessor; -use Automattic\WooCommerce\Admin\RemoteInboxNotifications\FailRuleProcessor; +use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\PublishAfterTimeRuleProcessor; +use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\FailRuleProcessor; /** * MockGetRuleProcessor. diff --git a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/not-rule-processor.php b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/not-rule-processor.php index ae85aeedf534..9088cec32426 100644 --- a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/not-rule-processor.php +++ b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/not-rule-processor.php @@ -5,8 +5,8 @@ * @package WooCommerce\Admin\Tests\RemoteInboxNotifications */ -use Automattic\WooCommerce\Admin\RemoteInboxNotifications\NotRuleProcessor; -use Automattic\WooCommerce\Admin\RemoteInboxNotifications\RuleEvaluator; +use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\NotRuleProcessor; +use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\RuleEvaluator; /** * class WC_Admin_Tests_RemoteInboxNotifications_NotRuleProcessor diff --git a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/onboarding-profile-rule-processor.php b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/onboarding-profile-rule-processor.php index 576abb10b6fa..097670b01153 100644 --- a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/onboarding-profile-rule-processor.php +++ b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/onboarding-profile-rule-processor.php @@ -5,7 +5,7 @@ * @package WooCommerce\Admin\Tests\RemoteInboxNotifications */ -use Automattic\WooCommerce\Admin\RemoteInboxNotifications\OnboardingProfileRuleProcessor; +use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\OnboardingProfileRuleProcessor; use Automattic\WooCommerce\Internal\Admin\Onboarding\OnboardingProfile; /** diff --git a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/option-rule-processor.php b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/option-rule-processor.php index 788908884c55..6e062f0ec7a8 100644 --- a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/option-rule-processor.php +++ b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/option-rule-processor.php @@ -5,7 +5,7 @@ * @package WooCommerce\Admin\Tests\RemoteInboxNotifications */ -use Automattic\WooCommerce\Admin\RemoteInboxNotifications\OptionRuleProcessor; +use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\OptionRuleProcessor; /** * class WC_Admin_Tests_RemoteInboxNotifications_OptionRuleProcessor diff --git a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/or-rule-processor.php b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/or-rule-processor.php index e1037e21963b..6c93dfd1fb8e 100644 --- a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/or-rule-processor.php +++ b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/or-rule-processor.php @@ -5,8 +5,8 @@ * @package WooCommerce\Admin\Tests\RemoteInboxNotifications */ -use Automattic\WooCommerce\Admin\RemoteInboxNotifications\OrRuleProcessor; -use Automattic\WooCommerce\Admin\RemoteInboxNotifications\RuleEvaluator; +use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\OrRuleProcessor; +use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\RuleEvaluator; /** * class WC_Admin_Tests_RemoteInboxNotifications_OrRuleProcessor diff --git a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/plugin-version-rule-processor.php b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/plugin-version-rule-processor.php index fdf687b69d17..a38fdbb9a637 100644 --- a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/plugin-version-rule-processor.php +++ b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/plugin-version-rule-processor.php @@ -5,7 +5,7 @@ * @package WooCommerce\Admin\Tests\RemoteInboxNotifications */ -use Automattic\WooCommerce\Admin\RemoteInboxNotifications\PluginVersionRuleProcessor; +use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\PluginVersionRuleProcessor; /** * class WC_Admin_Tests_RemoteInboxNotifications_PluginVersionRuleProcessor diff --git a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/plugins-activated-rule-processor.php b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/plugins-activated-rule-processor.php index 2a32ae241c71..41f478cedce7 100644 --- a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/plugins-activated-rule-processor.php +++ b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/plugins-activated-rule-processor.php @@ -5,7 +5,7 @@ * @package WooCommerce\Admin\Tests\RemoteInboxNotifications */ -use Automattic\WooCommerce\Admin\RemoteInboxNotifications\PluginsActivatedRuleProcessor; +use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\PluginsActivatedRuleProcessor; use Automattic\WooCommerce\Admin\PluginsProvider\PluginsProviderInterface; /** diff --git a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/product-count-rule-processor.php b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/product-count-rule-processor.php index 25e47121b515..a3ca1a8cb749 100644 --- a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/product-count-rule-processor.php +++ b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/product-count-rule-processor.php @@ -5,7 +5,7 @@ * @package WooCommerce\Admin\Tests\RemoteInboxNotifications */ -use Automattic\WooCommerce\Admin\RemoteInboxNotifications\ProductCountRuleProcessor; +use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\ProductCountRuleProcessor; /** * class WC_Admin_Tests_RemoteInboxNotifications_ProductCountRuleProcessor diff --git a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/publish-after-time-rule-processor.php b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/publish-after-time-rule-processor.php index 7bd30432c63a..9aec0acfcfd5 100644 --- a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/publish-after-time-rule-processor.php +++ b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/publish-after-time-rule-processor.php @@ -5,7 +5,7 @@ * @package WooCommerce\Admin\Tests\RemoteInboxNotifications */ -use Automattic\WooCommerce\Admin\RemoteInboxNotifications\PublishAfterTimeRuleProcessor; +use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\PublishAfterTimeRuleProcessor; use Automattic\WooCommerce\Admin\DateTimeProvider\DateTimeProviderInterface; /** diff --git a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/publish-before-time-rule-processor.php b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/publish-before-time-rule-processor.php index 96d93d6a1a35..0234df59c873 100644 --- a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/publish-before-time-rule-processor.php +++ b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/publish-before-time-rule-processor.php @@ -5,7 +5,7 @@ * @package WooCommerce\Admin\Tests\RemoteInboxNotifications */ -use Automattic\WooCommerce\Admin\RemoteInboxNotifications\PublishBeforeTimeRuleProcessor; +use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\PublishBeforeTimeRuleProcessor; use Automattic\WooCommerce\Admin\DateTimeProvider\DateTimeProviderInterface; /** diff --git a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/remote-inbox-notifications-engine.php b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/remote-inbox-notifications-engine.php index 74e88e317697..11238bc0e6e1 100644 --- a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/remote-inbox-notifications-engine.php +++ b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/remote-inbox-notifications-engine.php @@ -6,7 +6,7 @@ */ use Automattic\WooCommerce\Admin\RemoteInboxNotifications\RemoteInboxNotificationsEngine; -use Automattic\WooCommerce\Admin\RemoteInboxNotifications\DataSourcePoller; +use Automattic\WooCommerce\Admin\RemoteInboxNotifications\RemoteInboxNotificationsDataSourcePoller; use Automattic\WooCommerce\Admin\Notes\Note; /** @@ -21,7 +21,7 @@ public function setUp(): void { parent::setUp(); add_filter( - 'transient_woocommerce_admin_' . DataSourcePoller::ID . '_specs', + 'transient_woocommerce_admin_' . RemoteInboxNotificationsDataSourcePoller::ID . '_specs', function( $value ) { if ( $value ) { return $value; @@ -63,8 +63,8 @@ function( $value ) { */ public function tearDown(): void { parent::tearDown(); - delete_transient( 'woocommerce_admin_' . DataSourcePoller::ID . '_specs' ); - remove_all_filters( 'transient_woocommerce_admin_' . DataSourcePoller::ID . '_specs' ); + delete_transient( 'woocommerce_admin_' . RemoteInboxNotificationsDataSourcePoller::ID . '_specs' ); + remove_all_filters( 'transient_woocommerce_admin_' . RemoteInboxNotificationsDataSourcePoller::ID . '_specs' ); } diff --git a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/stored-state-rule-processor.php b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/stored-state-rule-processor.php index 075e58b8490f..47567a6627d0 100644 --- a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/stored-state-rule-processor.php +++ b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/stored-state-rule-processor.php @@ -5,8 +5,7 @@ * @package WooCommerce\Admin\Tests\RemoteInboxNotifications */ -use Automattic\WooCommerce\Admin\RemoteInboxNotifications\StoredStateRuleProcessor; -use Automattic\WooCommerce\Admin\RemoteInboxNotifications\RuleEvaluator; +use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\StoredStateRuleProcessor; /** * class WC_Admin_Tests_RemoteInboxNotifications_StoredStateRuleProcessor diff --git a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/total-payments-volume-processor.php b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/total-payments-volume-processor.php index a3c98ac4870f..d177dd8f9750 100644 --- a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/total-payments-volume-processor.php +++ b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/total-payments-volume-processor.php @@ -5,7 +5,7 @@ * @package WooCommerce\Admin\Tests\RemoteInboxNotification */ -use Automattic\WooCommerce\Admin\RemoteInboxNotifications\TotalPaymentsVolumeProcessor; +use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\TotalPaymentsVolumeProcessor; use Automattic\WooCommerce\Admin\API\Reports\Revenue\Query as RevenueQuery; /** diff --git a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/transformer-service.php b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/transformer-service.php index ac154b0e3cdd..6e6a9443f0f5 100644 --- a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/transformer-service.php +++ b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/transformer-service.php @@ -5,8 +5,8 @@ * @package WooCommerce\Admin\Tests\RemoteInboxNotifications */ -use Automattic\WooCommerce\Admin\RemoteInboxNotifications\Transformers\ArrayKeys; -use Automattic\WooCommerce\Admin\RemoteInboxNotifications\TransformerService; +use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers\ArrayKeys; +use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers\TransformerService; /** * class WC_Admin_Tests_RemoteInboxNotifications_TransformerService diff --git a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/wcadmin-active-for-rule-processor.php b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/wcadmin-active-for-rule-processor.php index 2b994a1aa79a..dca95841a922 100644 --- a/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/wcadmin-active-for-rule-processor.php +++ b/plugins/woocommerce/tests/legacy/unit-tests/woocommerce-admin/remote-inbox-notifications/wcadmin-active-for-rule-processor.php @@ -5,7 +5,7 @@ * @package WooCommerce\Admin\Tests\RemoteInboxNotification */ -use Automattic\WooCommerce\Admin\RemoteInboxNotifications\WCAdminActiveForRuleProcessor; +use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\WCAdminActiveForRuleProcessor; /** * class WC_Admin_Tests_RemoteInboxNotifications_WCAdminActiveForRuleProcessor diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/MarketingRecommendations/InitTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/MarketingRecommendations/InitTest.php index adaca4c18617..c4fb8a3f7152 100644 --- a/plugins/woocommerce/tests/php/src/Internal/Admin/MarketingRecommendations/InitTest.php +++ b/plugins/woocommerce/tests/php/src/Internal/Admin/MarketingRecommendations/InitTest.php @@ -2,7 +2,7 @@ namespace Automattic\WooCommerce\Tests\Internal\Admin\ShippingPartnerSuggestions; -use Automattic\WooCommerce\Admin\DataSourcePoller; +use Automattic\WooCommerce\Admin\RemoteSpecs\DataSourcePoller; use Automattic\WooCommerce\Admin\Features\MarketingRecommendations\Init; use Automattic\WooCommerce\Admin\Features\MarketingRecommendations\DefaultMarketingRecommendations; use Automattic\WooCommerce\Admin\Features\MarketingRecommendations\MarketingRecommendationsDataSourcePoller; diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/RemoteFreeExtensions/InitTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/RemoteFreeExtensions/InitTest.php index d2445e605330..f4af4a651170 100644 --- a/plugins/woocommerce/tests/php/src/Internal/Admin/RemoteFreeExtensions/InitTest.php +++ b/plugins/woocommerce/tests/php/src/Internal/Admin/RemoteFreeExtensions/InitTest.php @@ -2,7 +2,7 @@ namespace Automattic\WooCommerce\Tests\Internal\Admin\RemoteFreeExtensions; -use Automattic\WooCommerce\Admin\DataSourcePoller; +use Automattic\WooCommerce\Admin\RemoteSpecs\DataSourcePoller; use Automattic\WooCommerce\Internal\Admin\RemoteFreeExtensions\Init as RemoteFreeExtensions; use Automattic\WooCommerce\Internal\Admin\RemoteFreeExtensions\DefaultFreeExtensions; diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/ShippingPartnerSuggestions/ShippingPartnerSuggestionsTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/ShippingPartnerSuggestions/ShippingPartnerSuggestionsTest.php index 1a102d81563e..c5d46363fc61 100644 --- a/plugins/woocommerce/tests/php/src/Internal/Admin/ShippingPartnerSuggestions/ShippingPartnerSuggestionsTest.php +++ b/plugins/woocommerce/tests/php/src/Internal/Admin/ShippingPartnerSuggestions/ShippingPartnerSuggestionsTest.php @@ -2,7 +2,7 @@ namespace Automattic\WooCommerce\Tests\Internal\Admin\ShippingPartnerSuggestions; -use Automattic\WooCommerce\Admin\DataSourcePoller; +use Automattic\WooCommerce\Admin\RemoteSpecs\DataSourcePoller; use Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks\Shipping; use Automattic\WooCommerce\Admin\Features\ShippingPartnerSuggestions\DefaultShippingPartners; use Automattic\WooCommerce\Admin\Features\ShippingPartnerSuggestions\ShippingPartnerSuggestions; diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/WCPayPromotion/InitTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/WCPayPromotion/InitTest.php index 12b409e232b2..27fe4946a1d8 100644 --- a/plugins/woocommerce/tests/php/src/Internal/Admin/WCPayPromotion/InitTest.php +++ b/plugins/woocommerce/tests/php/src/Internal/Admin/WCPayPromotion/InitTest.php @@ -2,7 +2,7 @@ namespace Automattic\WooCommerce\Tests\Internal\Admin\WCPayPromotion; -use Automattic\WooCommerce\Admin\DataSourcePoller; +use Automattic\WooCommerce\Admin\RemoteSpecs\DataSourcePoller; use Automattic\WooCommerce\Internal\Admin\WCPayPromotion\Init as WCPayPromotion; use Automattic\WooCommerce\Internal\Admin\WCPayPromotion\WCPayPromotionDataSourcePoller;