Path: blob/master/src/applications/herald/engineextension/HeraldRuleIndexEngineExtension.php
12256 views
<?php12final class HeraldRuleIndexEngineExtension3extends PhabricatorEdgeIndexEngineExtension {45const EXTENSIONKEY = 'herald.actions';67public function getExtensionName() {8return pht('Herald Actions');9}1011public function shouldIndexObject($object) {12if (!($object instanceof HeraldRule)) {13return false;14}1516return true;17}1819protected function getIndexEdgeType() {20return HeraldRuleActionAffectsObjectEdgeType::EDGECONST;21}2223protected function getIndexDestinationPHIDs($object) {24$rule = $object;2526$viewer = $this->getViewer();2728$rule = id(new HeraldRuleQuery())29->setViewer($viewer)30->withIDs(array($rule->getID()))31->needConditionsAndActions(true)32->executeOne();33if (!$rule) {34return array();35}3637$phids = array();3839$fields = HeraldField::getAllFields();40foreach ($rule->getConditions() as $condition_record) {41$field = idx($fields, $condition_record->getFieldName());4243if (!$field) {44continue;45}4647$affected_phids = $field->getPHIDsAffectedByCondition($condition_record);48foreach ($affected_phids as $phid) {49$phids[] = $phid;50}51}5253$actions = HeraldAction::getAllActions();54foreach ($rule->getActions() as $action_record) {55$action = idx($actions, $action_record->getAction());5657if (!$action) {58continue;59}6061foreach ($action->getPHIDsAffectedByAction($action_record) as $phid) {62$phids[] = $phid;63}64}6566$phids = array_fuse($phids);67return array_keys($phids);68}6970}717273