protected function getRuleEffects(HeraldRule $rule, HeraldAdapter $object) { $effects = array(); foreach ($rule->getActions() as $action) { $effect = new HeraldEffect(); $effect->setObjectPHID($object->getPHID()); $effect->setAction($action->getAction()); $effect->setTarget($action->getTarget()); $effect->setRuleID($rule->getID()); $effect->setRulePHID($rule->getPHID()); $name = $rule->getName(); $id = $rule->getID(); $effect->setReason(pht('Conditions were met for %s', "H{$id} {$name}")); $effects[] = $effect; } return $effects; }
public function applyHeraldEffects(array $effects) { assert_instances_of($effects, 'HeraldEffect'); $result = array(); if ($this->explicitCCs) { $effect = new HeraldEffect(); $effect->setAction(HeraldActionConfig::ACTION_ADD_CC); $effect->setTarget(array_keys($this->explicitCCs)); $effect->setReason('CCs provided explicitly by revision author or carried over from a ' . 'previous version of the revision.'); $result[] = new HeraldApplyTranscript($effect, true, 'Added addresses to CC list.'); } $forbidden_ccs = array_fill_keys(nonempty($this->forbiddenCCs, array()), true); foreach ($effects as $effect) { $action = $effect->getAction(); switch ($action) { case HeraldActionConfig::ACTION_NOTHING: $result[] = new HeraldApplyTranscript($effect, true, 'OK, did nothing.'); break; case HeraldActionConfig::ACTION_FLAG: $result[] = parent::applyFlagEffect($effect, $this->revision->getPHID()); break; case HeraldActionConfig::ACTION_EMAIL: case HeraldActionConfig::ACTION_ADD_CC: $op = $action == HeraldActionConfig::ACTION_EMAIL ? 'email' : 'CC'; $base_target = $effect->getTarget(); $forbidden = array(); foreach ($base_target as $key => $fbid) { if (isset($forbidden_ccs[$fbid])) { $forbidden[] = $fbid; unset($base_target[$key]); } else { if ($action == HeraldActionConfig::ACTION_EMAIL) { $this->emailPHIDs[$fbid] = true; } else { $this->newCCs[$fbid] = true; } } } if ($forbidden) { $failed = clone $effect; $failed->setTarget($forbidden); if ($base_target) { $effect->setTarget($base_target); $result[] = new HeraldApplyTranscript($effect, true, 'Added these addresses to ' . $op . ' list. ' . 'Others could not be added.'); } $result[] = new HeraldApplyTranscript($failed, false, $op . ' forbidden, these addresses have unsubscribed.'); } else { $result[] = new HeraldApplyTranscript($effect, true, 'Added addresses to ' . $op . ' list.'); } break; case HeraldActionConfig::ACTION_REMOVE_CC: foreach ($effect->getTarget() as $fbid) { $this->remCCs[$fbid] = true; } $result[] = new HeraldApplyTranscript($effect, true, 'Removed addresses from CC list.'); break; default: throw new Exception("No rules to handle action '{$action}'."); } } return $result; }
protected function getRuleEffects(HeraldRule $rule, HeraldObjectAdapter $object) { $effects = array(); foreach ($rule->getActions() as $action) { $effect = new HeraldEffect(); $effect->setObjectPHID($object->getPHID()); $effect->setAction($action->getAction()); $effect->setTarget($action->getTarget()); $effect->setRuleID($rule->getID()); $name = $rule->getName(); $id = $rule->getID(); $effect->setReason('Conditions were met for Herald rule "' . $name . '" (#' . $id . ').'); $effects[] = $effect; } return $effects; }
public function applyHeraldEffects(array $effects) { assert_instances_of($effects, 'HeraldEffect'); $result = array(); if ($this->explicitCCs) { $effect = new HeraldEffect(); $effect->setAction(self::ACTION_ADD_CC); $effect->setTarget(array_keys($this->explicitCCs)); $effect->setReason(pht('CCs provided explicitly by revision author or carried over ' . 'from a previous version of the revision.')); $result[] = new HeraldApplyTranscript($effect, true, pht('Added addresses to CC list.')); } $forbidden_ccs = array_fill_keys(nonempty($this->forbiddenCCs, array()), true); foreach ($effects as $effect) { $action = $effect->getAction(); switch ($action) { case self::ACTION_NOTHING: $result[] = new HeraldApplyTranscript($effect, true, pht('OK, did nothing.')); break; case self::ACTION_FLAG: $result[] = parent::applyFlagEffect($effect, $this->revision->getPHID()); break; case self::ACTION_EMAIL: case self::ACTION_ADD_CC: $op = $action == self::ACTION_EMAIL ? 'email' : 'CC'; $base_target = $effect->getTarget(); $forbidden = array(); foreach ($base_target as $key => $fbid) { if (isset($forbidden_ccs[$fbid])) { $forbidden[] = $fbid; unset($base_target[$key]); } else { if ($action == self::ACTION_EMAIL) { $this->emailPHIDs[$fbid] = true; } else { $this->newCCs[$fbid] = true; } } } if ($forbidden) { $failed = clone $effect; $failed->setTarget($forbidden); if ($base_target) { $effect->setTarget($base_target); $result[] = new HeraldApplyTranscript($effect, true, pht('Added these addresses to %s list. ' . 'Others could not be added.', $op)); } $result[] = new HeraldApplyTranscript($failed, false, pht('%s forbidden, these addresses have unsubscribed.', $op)); } else { $result[] = new HeraldApplyTranscript($effect, true, pht('Added addresses to %s list.', $op)); } break; case self::ACTION_REMOVE_CC: foreach ($effect->getTarget() as $fbid) { $this->remCCs[$fbid] = true; } $result[] = new HeraldApplyTranscript($effect, true, pht('Removed addresses from CC list.')); break; case self::ACTION_ADD_REVIEWERS: foreach ($effect->getTarget() as $phid) { $this->addReviewerPHIDs[$phid] = true; } $result[] = new HeraldApplyTranscript($effect, true, pht('Added reviewers.')); break; case self::ACTION_ADD_BLOCKING_REVIEWERS: // This adds reviewers normally, it just also marks them blocking. foreach ($effect->getTarget() as $phid) { $this->addReviewerPHIDs[$phid] = true; $this->blockingReviewerPHIDs[$phid] = true; } $result[] = new HeraldApplyTranscript($effect, true, pht('Added blocking reviewers.')); break; case self::ACTION_APPLY_BUILD_PLANS: foreach ($effect->getTarget() as $phid) { $this->buildPlans[] = $phid; } $result[] = new HeraldApplyTranscript($effect, true, pht('Applied build plans.')); break; case self::ACTION_REQUIRE_SIGNATURE: foreach ($effect->getTarget() as $phid) { $this->requiredSignatureDocumentPHIDs[] = $phid; } $result[] = new HeraldApplyTranscript($effect, true, pht('Required signatures.')); break; default: $custom_result = parent::handleCustomHeraldEffect($effect); if ($custom_result === null) { throw new Exception(pht("No rules to handle action '%s'.", $action)); } $result[] = $custom_result; break; } } return $result; }