Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/herald/engineextension/HeraldRuleIndexEngineExtension.php
12256 views
1
<?php
2
3
final class HeraldRuleIndexEngineExtension
4
extends PhabricatorEdgeIndexEngineExtension {
5
6
const EXTENSIONKEY = 'herald.actions';
7
8
public function getExtensionName() {
9
return pht('Herald Actions');
10
}
11
12
public function shouldIndexObject($object) {
13
if (!($object instanceof HeraldRule)) {
14
return false;
15
}
16
17
return true;
18
}
19
20
protected function getIndexEdgeType() {
21
return HeraldRuleActionAffectsObjectEdgeType::EDGECONST;
22
}
23
24
protected function getIndexDestinationPHIDs($object) {
25
$rule = $object;
26
27
$viewer = $this->getViewer();
28
29
$rule = id(new HeraldRuleQuery())
30
->setViewer($viewer)
31
->withIDs(array($rule->getID()))
32
->needConditionsAndActions(true)
33
->executeOne();
34
if (!$rule) {
35
return array();
36
}
37
38
$phids = array();
39
40
$fields = HeraldField::getAllFields();
41
foreach ($rule->getConditions() as $condition_record) {
42
$field = idx($fields, $condition_record->getFieldName());
43
44
if (!$field) {
45
continue;
46
}
47
48
$affected_phids = $field->getPHIDsAffectedByCondition($condition_record);
49
foreach ($affected_phids as $phid) {
50
$phids[] = $phid;
51
}
52
}
53
54
$actions = HeraldAction::getAllActions();
55
foreach ($rule->getActions() as $action_record) {
56
$action = idx($actions, $action_record->getAction());
57
58
if (!$action) {
59
continue;
60
}
61
62
foreach ($action->getPHIDsAffectedByAction($action_record) as $phid) {
63
$phids[] = $phid;
64
}
65
}
66
67
$phids = array_fuse($phids);
68
return array_keys($phids);
69
}
70
71
}
72
73