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
EvaluateAndGetStatus.php
67 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Evaluates the spec and returns a status. |
| 4 | */ |
| 5 | |
| 6 | namespace Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors; |
| 7 | |
| 8 | defined( 'ABSPATH' ) || exit; |
| 9 | |
| 10 | use Automattic\WooCommerce\Admin\Notes\Note; |
| 11 | |
| 12 | /** |
| 13 | * Evaluates the spec and returns a status. |
| 14 | */ |
| 15 | class EvaluateAndGetStatus { |
| 16 | /** |
| 17 | * Evaluates the spec and returns a status. |
| 18 | * |
| 19 | * @param array $spec The spec to evaluate. |
| 20 | * @param string $current_status The note's current status. |
| 21 | * @param object $stored_state Stored state. |
| 22 | * @param object $rule_evaluator Evaluates rules into true/false. |
| 23 | * |
| 24 | * @return string The evaluated status. |
| 25 | */ |
| 26 | public static function evaluate( $spec, $current_status, $stored_state, $rule_evaluator ) { |
| 27 | // No rules should leave the note alone. |
| 28 | if ( ! isset( $spec->rules ) ) { |
| 29 | return $current_status; |
| 30 | } |
| 31 | |
| 32 | $evaluated_result = $rule_evaluator->evaluate( |
| 33 | $spec->rules, |
| 34 | $stored_state, |
| 35 | array( |
| 36 | 'slug' => $spec->slug, |
| 37 | 'source' => 'remote-inbox-notifications', |
| 38 | ) |
| 39 | ); |
| 40 | |
| 41 | // Pending notes should be the spec status if the spec passes, |
| 42 | // left alone otherwise. |
| 43 | if ( Note::E_WC_ADMIN_NOTE_PENDING === $current_status ) { |
| 44 | return $evaluated_result |
| 45 | ? $spec->status |
| 46 | : Note::E_WC_ADMIN_NOTE_PENDING; |
| 47 | } |
| 48 | |
| 49 | // If the spec is an alert type and the note is unactioned, set to pending if the spec no longer applies. |
| 50 | if ( isset( $spec->type ) && in_array( $spec->type, array( 'error', 'update' ), true ) |
| 51 | && Note::E_WC_ADMIN_NOTE_UNACTIONED === $current_status |
| 52 | && ! $evaluated_result ) { |
| 53 | return Note::E_WC_ADMIN_NOTE_PENDING; |
| 54 | } |
| 55 | |
| 56 | // When allow_redisplay isn't set, just leave the note alone. |
| 57 | if ( ! isset( $spec->allow_redisplay ) || ! $spec->allow_redisplay ) { |
| 58 | return $current_status; |
| 59 | } |
| 60 | |
| 61 | // allow_redisplay is set, unaction the note if eval to true. |
| 62 | return $evaluated_result |
| 63 | ? Note::E_WC_ADMIN_NOTE_UNACTIONED |
| 64 | : $current_status; |
| 65 | } |
| 66 | } |
| 67 |