Transformers
1 year ago
BaseLocationCountryRuleProcessor.php
2 years ago
BaseLocationStateRuleProcessor.php
2 years ago
ComparisonOperation.php
2 years ago
ContextPluginsRuleProcessor.php
1 year ago
EvaluateAndGetStatus.php
2 years ago
EvaluateOverrides.php
1 year ago
EvaluationLogger.php
1 year ago
FailRuleProcessor.php
2 years ago
GetRuleProcessor.php
2 years ago
GetRuleProcessorForContext.php
1 year ago
IsEcommerceRuleProcessor.php
2 years ago
IsWooExpressRuleProcessor.php
2 years ago
NotRuleProcessor.php
2 years ago
NoteStatusRuleProcessor.php
2 years ago
OnboardingProfileRuleProcessor.php
2 years ago
OptionRuleProcessor.php
2 years ago
OrRuleProcessor.php
2 years ago
OrderCountRuleProcessor.php
2 years ago
OrdersProvider.php
2 years ago
PassRuleProcessor.php
2 years ago
PluginVersionRuleProcessor.php
2 years ago
PluginsActivatedRuleProcessor.php
2 years ago
ProductCountRuleProcessor.php
1 year ago
PublishAfterTimeRuleProcessor.php
2 years ago
PublishBeforeTimeRuleProcessor.php
2 years ago
RuleEvaluator.php
1 year ago
RuleProcessorInterface.php
2 years ago
StoredStateRuleProcessor.php
2 years ago
StoredStateSetupForProducts.php
2 years ago
TotalPaymentsVolumeProcessor.php
1 year ago
WCAdminActiveForProvider.php
2 years ago
WCAdminActiveForRuleProcessor.php
2 years ago
WooCommerceAdminUpdatedRuleProcessor.php
2 years ago
WCAdminActiveForRuleProcessor.php
80 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Rule processor for publishing if wc-admin has been active for at least the |
| 4 | * given number of seconds. |
| 5 | */ |
| 6 | |
| 7 | namespace Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors; |
| 8 | |
| 9 | defined( 'ABSPATH' ) || exit; |
| 10 | |
| 11 | /** |
| 12 | * Rule processor for publishing if wc-admin has been active for at least the |
| 13 | * given number of seconds. |
| 14 | */ |
| 15 | class WCAdminActiveForRuleProcessor implements RuleProcessorInterface { |
| 16 | |
| 17 | /** |
| 18 | * Provides the amount of time wcadmin has been active for. |
| 19 | * |
| 20 | * @var WCAdminActiveForProvider |
| 21 | */ |
| 22 | protected $wcadmin_active_for_provider; |
| 23 | |
| 24 | /** |
| 25 | * Constructor |
| 26 | * |
| 27 | * @param object $wcadmin_active_for_provider Provides the amount of time wcadmin has been active for. |
| 28 | */ |
| 29 | public function __construct( $wcadmin_active_for_provider = null ) { |
| 30 | $this->wcadmin_active_for_provider = null === $wcadmin_active_for_provider |
| 31 | ? new WCAdminActiveForProvider() |
| 32 | : $wcadmin_active_for_provider; |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Performs a comparison operation against the amount of time wc-admin has |
| 37 | * been active for in days. |
| 38 | * |
| 39 | * @param object $rule The rule being processed. |
| 40 | * @param object $stored_state Stored state. |
| 41 | * |
| 42 | * @return bool The result of the operation. |
| 43 | */ |
| 44 | public function process( $rule, $stored_state ) { |
| 45 | $active_for_seconds = $this->wcadmin_active_for_provider->get_wcadmin_active_for_in_seconds(); |
| 46 | |
| 47 | if ( ! $active_for_seconds || ! is_numeric( $active_for_seconds ) || $active_for_seconds < 0 ) { |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | $rule_seconds = $rule->days * DAY_IN_SECONDS; |
| 52 | |
| 53 | return ComparisonOperation::compare( |
| 54 | $active_for_seconds, |
| 55 | $rule_seconds, |
| 56 | $rule->operation |
| 57 | ); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Validates the rule. |
| 62 | * |
| 63 | * @param object $rule The rule to validate. |
| 64 | * |
| 65 | * @return bool Pass/fail. |
| 66 | */ |
| 67 | public function validate( $rule ) { |
| 68 | // Ensure that 'days' property is set and is a valid numeric value. |
| 69 | if ( ! isset( $rule->days ) || ! is_numeric( $rule->days ) || $rule->days < 0 ) { |
| 70 | return false; |
| 71 | } |
| 72 | |
| 73 | if ( ! isset( $rule->operation ) ) { |
| 74 | return false; |
| 75 | } |
| 76 | |
| 77 | return true; |
| 78 | } |
| 79 | } |
| 80 |