Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / herald / engineextension / HeraldRuleIndexEngineExtension.php
blobca28116d4c517126a285a4cb22d74a553f6ed87a
1 <?php
3 final class HeraldRuleIndexEngineExtension
4 extends PhabricatorEdgeIndexEngineExtension {
6 const EXTENSIONKEY = 'herald.actions';
8 public function getExtensionName() {
9 return pht('Herald Actions');
12 public function shouldIndexObject($object) {
13 if (!($object instanceof HeraldRule)) {
14 return false;
17 return true;
20 protected function getIndexEdgeType() {
21 return HeraldRuleActionAffectsObjectEdgeType::EDGECONST;
24 protected function getIndexDestinationPHIDs($object) {
25 $rule = $object;
27 $viewer = $this->getViewer();
29 $rule = id(new HeraldRuleQuery())
30 ->setViewer($viewer)
31 ->withIDs(array($rule->getID()))
32 ->needConditionsAndActions(true)
33 ->executeOne();
34 if (!$rule) {
35 return array();
38 $phids = array();
40 $fields = HeraldField::getAllFields();
41 foreach ($rule->getConditions() as $condition_record) {
42 $field = idx($fields, $condition_record->getFieldName());
44 if (!$field) {
45 continue;
48 $affected_phids = $field->getPHIDsAffectedByCondition($condition_record);
49 foreach ($affected_phids as $phid) {
50 $phids[] = $phid;
54 $actions = HeraldAction::getAllActions();
55 foreach ($rule->getActions() as $action_record) {
56 $action = idx($actions, $action_record->getAction());
58 if (!$action) {
59 continue;
62 foreach ($action->getPHIDsAffectedByAction($action_record) as $phid) {
63 $phids[] = $phid;
67 $phids = array_fuse($phids);
68 return array_keys($phids);