Path: blob/master/src/applications/herald/storage/transcript/HeraldRuleResult.php
12262 views
<?php12final class HeraldRuleResult3extends HeraldTranscriptResult {45const RESULT_ANY_MATCHED = 'any-match';6const RESULT_ALL_MATCHED = 'all-match';7const RESULT_ANY_FAILED = 'any-failed';8const RESULT_ALL_FAILED = 'all-failed';9const RESULT_LAST_MATCHED = 'last-match';10const RESULT_VERSION = 'version';11const RESULT_EMPTY = 'empty';12const RESULT_OWNER = 'owner';13const RESULT_VIEW_POLICY = 'view-policy';14const RESULT_OBJECT_RULE = 'object-rule';15const RESULT_EXCEPTION = 'exception';16const RESULT_EVALUATION_EXCEPTION = 'evaluation-exception';17const RESULT_UNKNOWN = 'unknown';18const RESULT_ALREADY_APPLIED = 'already-applied';19const RESULT_OBJECT_STATE = 'object-state';20const RESULT_RECURSION = 'recursion';2122public static function newFromResultCode($result_code) {23return id(new self())->setResultCode($result_code);24}2526public static function newFromResultMap(array $map) {27return id(new self())->loadFromResultMap($map);28}2930public function getShouldRecordMatch() {31return ($this->getSpecificationProperty('match') === true);32}3334public function getShouldApplyActions() {35return ($this->getSpecificationProperty('apply') === true);36}3738public function getDescription() {39return $this->getSpecificationProperty('description');40}4142public function newDetailsView(PhabricatorUser $viewer) {43switch ($this->getResultCode()) {44case self::RESULT_EXCEPTION:45$error_class = $this->getDataProperty('exception.class');46$error_message = $this->getDataProperty('exception.message');4748if (!strlen($error_class)) {49$error_class = pht('Unknown Error');50}5152if (!strlen($error_message)) {53$error_message = pht(54'An unknown error occurred while evaluating this condition. No '.55'additional information is available.');56}5758$details = $this->newErrorView($error_class, $error_message);59break;60case self::RESULT_RECURSION:61$rule_phids = $this->getDataProperty('cyclePHIDs', array());62$handles = $viewer->loadHandles($rule_phids);6364$links = array();65foreach ($rule_phids as $rule_phid) {66$links[] = $handles[$rule_phid]->renderLink();67}6869$links = phutil_implode_html(' > ', $links);7071$details = array(72pht('This rule has a dependency cycle and can not be evaluated:'),73' ',74$links,75);76break;77default:78$details = null;79break;80}8182return $details;83}8485protected function newResultSpecificationMap() {86return array(87self::RESULT_ANY_MATCHED => array(88'match' => true,89'apply' => true,90'name' => pht('Matched'),91'description' => pht('Any condition matched.'),92'icon' => 'fa-check-circle',93'color.icon' => 'green',94),95self::RESULT_ALL_MATCHED => array(96'match' => true,97'apply' => true,98'name' => pht('Matched'),99'description' => pht('All conditions matched.'),100'icon' => 'fa-check-circle',101'color.icon' => 'green',102),103self::RESULT_ANY_FAILED => array(104'match' => false,105'apply' => false,106'name' => pht('Failed'),107'description' => pht('Not all conditions matched.'),108'icon' => 'fa-times-circle',109'color.icon' => 'red',110),111self::RESULT_ALL_FAILED => array(112'match' => false,113'apply' => false,114'name' => pht('Failed'),115'description' => pht('No conditions matched.'),116'icon' => 'fa-times-circle',117'color.icon' => 'red',118),119self::RESULT_LAST_MATCHED => array(120'match' => true,121'apply' => false,122'name' => pht('Failed'),123'description' => pht(124'This rule matched, but did not take any actions because it '.125'is configured to act only if it did not match the last time.'),126'icon' => 'fa-times-circle',127'color.icon' => 'red',128),129self::RESULT_VERSION => array(130'match' => null,131'apply' => false,132'name' => pht('Version Issue'),133'description' => pht(134'Rule could not be processed because it was created with a newer '.135'version of Herald.'),136'icon' => 'fa-times-circle',137'color.icon' => 'red',138),139self::RESULT_EMPTY => array(140'match' => null,141'apply' => false,142'name' => pht('Empty'),143'description' => pht(144'Rule failed automatically because it has no conditions.'),145'icon' => 'fa-times-circle',146'color.icon' => 'red',147),148self::RESULT_OWNER => array(149'match' => null,150'apply' => false,151'name' => pht('Rule Owner'),152'description' => pht(153'Rule failed automatically because it is a personal rule and '.154'its owner is invalid or disabled.'),155'icon' => 'fa-times-circle',156'color.icon' => 'red',157),158self::RESULT_VIEW_POLICY => array(159'match' => null,160'apply' => false,161'name' => pht('View Policy'),162'description' => pht(163'Rule failed automatically because it is a personal rule and '.164'its owner does not have permission to view the object.'),165'icon' => 'fa-times-circle',166'color.icon' => 'red',167),168self::RESULT_OBJECT_RULE => array(169'match' => null,170'apply' => false,171'name' => pht('Object Rule'),172'description' => pht(173'Rule failed automatically because it is an object rule which is '.174'not relevant for this object.'),175'icon' => 'fa-times-circle',176'color.icon' => 'red',177),178self::RESULT_EXCEPTION => array(179'match' => null,180'apply' => false,181'name' => pht('Exception'),182'description' => pht(183'Rule failed because an exception occurred.'),184'icon' => 'fa-times-circle',185'color.icon' => 'red',186),187self::RESULT_EVALUATION_EXCEPTION => array(188'match' => null,189'apply' => false,190'name' => pht('Exception'),191'description' => pht(192'Rule failed because an exception occurred while evaluating it.'),193'icon' => 'fa-times-circle',194'color.icon' => 'red',195),196self::RESULT_UNKNOWN => array(197'match' => null,198'apply' => false,199'name' => pht('Unknown'),200'description' => pht(201'Rule evaluation result is unknown.'),202'icon' => 'fa-times-circle',203'color.icon' => 'red',204),205self::RESULT_ALREADY_APPLIED => array(206'match' => null,207'apply' => false,208'name' => pht('Already Applied'),209'description' => pht(210'This rule is only supposed to be repeated a single time, '.211'and it has already been applied.'),212'icon' => 'fa-times-circle',213'color.icon' => 'red',214),215self::RESULT_OBJECT_STATE => array(216'match' => null,217'apply' => false,218'name' => pht('Forbidden'),219'description' => pht(220'Object state prevented rule evaluation.'),221'icon' => 'fa-ban',222'color.icon' => 'indigo',223),224self::RESULT_RECURSION => array(225'match' => null,226'apply' => false,227'name' => pht('Recursion'),228'description' => pht(229'This rule has a recursive dependency on itself and can not '.230'be evaluated.'),231'icon' => 'fa-times-circle',232'color.icon' => 'red',233),234);235}236237}238239240