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