rebase on oct-10-2023

This commit is contained in:
Rachit Bhargava
2023-10-10 17:23:21 -04:00
parent d37566ffb6
commit d096058d7d
4789 changed files with 254611 additions and 307223 deletions

View File

@@ -29,8 +29,12 @@ class BaseLocationCountryRuleProcessor implements RuleProcessorInterface {
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 ( 'US' === $base_location['country'] && 'CA' === $base_location['state'] && empty( get_option( 'woocommerce_store_address', '' ) ) && OnboardingProfile::needs_completion() ) {
if ( $is_address_default && OnboardingProfile::needs_completion() && ! $is_store_country_set ) {
return false;
}

View File

@@ -33,9 +33,15 @@ class ComparisonOperation {
case '!=':
return $left_operand !== $right_operand;
case 'contains':
return in_array( $right_operand, $left_operand, true );
if ( is_array( $left_operand ) && is_string( $right_operand ) ) {
return in_array( $right_operand, $left_operand, true );
}
return strpos( $right_operand, $left_operand ) !== false;
case '!contains':
return ! in_array( $right_operand, $left_operand, true );
if ( is_array( $left_operand ) && is_string( $right_operand ) ) {
return ! in_array( $right_operand, $left_operand, true );
}
return strpos( $right_operand, $left_operand ) === false;
}
return false;

View File

@@ -11,6 +11,14 @@ defined( 'ABSPATH' ) || exit;
* Rule processor that negates the rules in the rule's operand.
*/
class NotRuleProcessor implements RuleProcessorInterface {
/**
* The rule evaluator to use.
*
* @var RuleEvaluator
*/
protected $rule_evaluator;
/**
* Constructor.
*

View File

@@ -23,9 +23,33 @@ class OptionRuleProcessor implements RuleProcessorInterface {
$is_contains = $rule->operation && strpos( $rule->operation, 'contains' ) !== false;
$default_value = $is_contains ? array() : false;
$default = isset( $rule->default ) ? $rule->default : $default_value;
$option_value = get_option( $rule->option_name, $default );
$option_value = $this->get_option_value( $rule, $default, $is_contains );
if ( $is_contains && ! is_array( $option_value ) ) {
if ( isset( $rule->transformers ) && is_array( $rule->transformers ) ) {
$option_value = TransformerService::apply( $option_value, $rule->transformers, $default );
}
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 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, $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(
@@ -41,15 +65,7 @@ class OptionRuleProcessor implements RuleProcessorInterface {
$option_value = array();
}
if ( isset( $rule->transformers ) && is_array( $rule->transformers ) ) {
$option_value = TransformerService::apply( $option_value, $rule->transformers, $default );
}
return ComparisonOperation::compare(
$option_value,
$rule->value,
$rule->operation
);
return $option_value;
}
/**

View File

@@ -13,6 +13,15 @@ defined( 'ABSPATH' ) || exit;
* operands.
*/
class OrRuleProcessor implements RuleProcessorInterface {
/**
* Rule evaluator to use.
*
* @var RuleEvaluator
*/
private $rule_evaluator;
/**
* Constructor.
*

View File

@@ -11,6 +11,14 @@ defined( 'ABSPATH' ) || exit;
* Rule processor for publishing based on the number of orders.
*/
class OrderCountRuleProcessor implements RuleProcessorInterface {
/**
* The orders provider.
*
* @var OrdersProvider
*/
protected $orders_provider;
/**
* Constructor.
*

View File

@@ -15,6 +15,15 @@ use Automattic\WooCommerce\Admin\PluginsProvider\PluginsProvider;
* matches the specified version.
*/
class PluginVersionRuleProcessor implements RuleProcessorInterface {
/**
* Plugins provider instance.
*
* @var PluginsProviderInterface
*/
private $plugins_provider;
/**
* Constructor.
*

View File

@@ -13,6 +13,14 @@ use Automattic\WooCommerce\Admin\PluginsProvider\PluginsProvider;
* Rule processor for sending when the provided plugins are activated.
*/
class PluginsActivatedRuleProcessor implements RuleProcessorInterface {
/**
* The plugins provider.
*
* @var PluginsProviderInterface
*/
protected $plugins_provider;
/**
* Constructor.
*

View File

@@ -13,6 +13,14 @@ defined( 'ABSPATH' ) || exit;
* products.
*/
class ProductCountRuleProcessor implements RuleProcessorInterface {
/**
* The product query.
*
* @var WC_Product_Query
*/
protected $product_query;
/**
* Constructor.
*

View File

@@ -13,6 +13,14 @@ use Automattic\WooCommerce\Admin\DateTimeProvider\CurrentDateTimeProvider;
* Rule processor for sending after a specified date/time.
*/
class PublishAfterTimeRuleProcessor implements RuleProcessorInterface {
/**
* The DateTime provider.
*
* @var DateTimeProviderInterface
*/
protected $date_time_provider;
/**
* Constructor.
*

View File

@@ -13,6 +13,14 @@ use Automattic\WooCommerce\Admin\DateTimeProvider\CurrentDateTimeProvider;
* Rule processor for sending before a specified date/time.
*/
class PublishBeforeTimeRuleProcessor implements RuleProcessorInterface {
/**
* The DateTime provider.
*
* @var DateTimeProviderInterface
*/
protected $date_time_provider;
/**
* Constructor.
*

View File

@@ -40,19 +40,20 @@ class RemoteInboxNotificationsEngine {
// Hook into WCA updated. This is hooked up here rather than in
// on_admin_init because that runs too late to hook into the action.
add_action( 'woocommerce_run_on_woocommerce_admin_updated', array( __CLASS__, 'run_on_woocommerce_admin_updated' ) );
add_action(
'woocommerce_updated',
function() {
$next_hook = WC()->queue()->get_next(
'woocommerce_run_on_woocommerce_admin_updated',
array( __CLASS__, 'run_on_woocommerce_admin_updated' ),
array(),
'woocommerce-remote-inbox-engine'
);
if ( null === $next_hook ) {
WC()->queue()->schedule_single(
time(),
'woocommerce_run_on_woocommerce_admin_updated',
array( __CLASS__, 'run_on_woocommerce_admin_updated' ),
array(),
'woocommerce-remote-inbox-engine'
);
}
@@ -205,9 +206,19 @@ class RemoteInboxNotificationsEngine {
break;
}
$localized_actions = SpecRunner::get_actions( $spec );
// Manually copy the action id from the db to the localized action, since they were not being provided.
foreach ( $localized_actions as $localized_action ) {
$action = $note_from_db->get_action( $localized_action->name );
if ( $action ) {
$localized_action->id = $action->id;
}
}
$note_from_db->set_title( $locale->title );
$note_from_db->set_content( $locale->content );
$note_from_db->set_actions( SpecRunner::get_actions( $spec ) );
$note_from_db->set_actions( $localized_actions );
}
return $note_from_db;

View File

@@ -13,6 +13,14 @@ defined( 'ABSPATH' ) || exit;
* rule evaluates to false.
*/
class RuleEvaluator {
/**
* GetRuleProcessor to use.
*
* @var GetRuleProcessor
*/
private $get_rule_processor;
/**
* Constructor.
*

View File

@@ -0,0 +1,38 @@
<?php
namespace Automattic\WooCommerce\Admin\RemoteInboxNotifications\Transformers;
use Automattic\WooCommerce\Admin\RemoteInboxNotifications\TransformerInterface;
use stdClass;
/**
* Prepare site URL for comparison.
*
* @package Automattic\WooCommerce\Admin\RemoteInboxNotifications\Transformers
*/
class PrepareUrl implements TransformerInterface {
/**
* Prepares the site URL by removing the protocol and trailing slash.
*
* @param mixed $value a value to transform.
* @param stdClass|null $arguments arguments.
* @param string|null $default default value.
*
* @return mixed|null
*/
public function transform( $value, stdClass $arguments = null, $default = null ) {
$url_parts = wp_parse_url( rtrim( $value, '/' ) );
return isset( $url_parts['path'] ) ? $url_parts['host'] . $url_parts['path'] : $url_parts['host'];
}
/**
* Validate Transformer arguments.
*
* @param stdClass|null $arguments arguments to validate.
*
* @return mixed
*/
public function validate( stdClass $arguments = null ) {
return true;
}
}

View File

@@ -13,6 +13,14 @@ defined( 'ABSPATH' ) || exit;
* given number of seconds.
*/
class WCAdminActiveForRuleProcessor implements RuleProcessorInterface {
/**
* Provides the amount of time wcadmin has been active for.
*
* @var WCAdminActiveForProvider
*/
protected $wcadmin_active_for_provider;
/**
* Constructor
*