private function buildPropertySectionView(HeraldRule $rule) { $viewer = $this->getRequest()->getUser(); $view = id(new PHUIPropertyListView())->setUser($viewer); $view->addProperty(pht('Rule Type'), idx(HeraldRuleTypeConfig::getRuleTypeMap(), $rule->getRuleType())); if ($rule->isPersonalRule()) { $view->addProperty(pht('Author'), $viewer->renderHandle($rule->getAuthorPHID())); } $adapter = HeraldAdapter::getAdapterForContentType($rule->getContentType()); if ($adapter) { $view->addProperty(pht('Applies To'), idx(HeraldAdapter::getEnabledAdapterMap($viewer), $rule->getContentType())); if ($rule->isObjectRule()) { $view->addProperty(pht('Trigger Object'), $viewer->renderHandle($rule->getTriggerObjectPHID())); } } return $view; }
private function canRuleApplyToObject(HeraldRule $rule, HeraldAdapter $adapter) { // Rules which are not object rules can apply to anything. if (!$rule->isObjectRule()) { return true; } $trigger_phid = $rule->getTriggerObjectPHID(); $object_phids = $adapter->getTriggerObjectPHIDs(); if ($object_phids) { if (in_array($trigger_phid, $object_phids)) { return true; } } return false; }
/** * Load rules for the "Another Herald rule..." condition dropdown, which * allows one rule to depend upon the success or failure of another rule. */ private function loadRulesThisRuleMayDependUpon(HeraldRule $rule) { $viewer = $this->getRequest()->getUser(); // Any rule can depend on a global rule. $all_rules = id(new HeraldRuleQuery())->setViewer($viewer)->withRuleTypes(array(HeraldRuleTypeConfig::RULE_TYPE_GLOBAL))->withContentTypes(array($rule->getContentType()))->execute(); if ($rule->isObjectRule()) { // Object rules may depend on other rules for the same object. $all_rules += id(new HeraldRuleQuery())->setViewer($viewer)->withRuleTypes(array(HeraldRuleTypeConfig::RULE_TYPE_OBJECT))->withContentTypes(array($rule->getContentType()))->withTriggerObjectPHIDs(array($rule->getTriggerObjectPHID()))->execute(); } if ($rule->isPersonalRule()) { // Personal rules may depend upon your other personal rules. $all_rules += id(new HeraldRuleQuery())->setViewer($viewer)->withRuleTypes(array(HeraldRuleTypeConfig::RULE_TYPE_PERSONAL))->withContentTypes(array($rule->getContentType()))->withAuthorPHIDs(array($rule->getAuthorPHID()))->execute(); } // mark disabled rules as disabled since they are not useful as such; // don't filter though to keep edit cases sane / expected foreach ($all_rules as $current_rule) { if ($current_rule->getIsDisabled()) { $current_rule->makeEphemeral(); $current_rule->setName($rule->getName() . ' ' . pht('(Disabled)')); } } // A rule can not depend upon itself. unset($all_rules[$rule->getID()]); return $all_rules; }
/** * Given a @{class:HeraldRule}, this function extracts all the phids that * we'll want to load as handles later. * * This function performs a somewhat hacky approach to figuring out what * is and is not a phid - try to get the phid type and if the type is * *not* unknown assume its a valid phid. * * Don't try this at home. Use more strongly typed data at home. * * Think of the children. */ public static function getHandlePHIDs(HeraldRule $rule) { $phids = array($rule->getAuthorPHID()); foreach ($rule->getConditions() as $condition) { $value = $condition->getValue(); if (!is_array($value)) { $value = array($value); } foreach ($value as $val) { if (phid_get_type($val) != PhabricatorPHIDConstants::PHID_TYPE_UNKNOWN) { $phids[] = $val; } } } foreach ($rule->getActions() as $action) { $target = $action->getTarget(); if (!is_array($target)) { $target = array($target); } foreach ($target as $val) { if (phid_get_type($val) != PhabricatorPHIDConstants::PHID_TYPE_UNKNOWN) { $phids[] = $val; } } } if ($rule->isObjectRule()) { $phids[] = $rule->getTriggerObjectPHID(); } return $phids; }