public function applyEffects(array $effects, HeraldObjectAdapter $object, array $rules) { assert_instances_of($effects, 'HeraldEffect'); assert_instances_of($rules, 'HeraldRule'); $this->transcript->setDryRun($object instanceof HeraldDryRunAdapter); $xscripts = $object->applyHeraldEffects($effects); foreach ($xscripts as $apply_xscript) { if (!$apply_xscript instanceof HeraldApplyTranscript) { throw new Exception("Heraldable must return HeraldApplyTranscripts from " . "applyHeraldEffect()."); } $this->transcript->addApplyTranscript($apply_xscript); } if (!$this->transcript->getDryRun()) { $rules = mpull($rules, null, 'getID'); $applied_ids = array(); $first_policy = HeraldRepetitionPolicyConfig::toInt(HeraldRepetitionPolicyConfig::FIRST); // Mark all the rules that have had their effects applied as having been // executed for the current object. $rule_ids = mpull($xscripts, 'getRuleID'); foreach ($rule_ids as $rule_id) { if (!$rule_id) { // Some apply transcripts are purely informational and not associated // with a rule, e.g. carryover emails from earlier revisions. continue; } $rule = idx($rules, $rule_id); if (!$rule) { continue; } if ($rule->getRepetitionPolicy() == $first_policy) { $applied_ids[] = $rule_id; } } if ($applied_ids) { $conn_w = id(new HeraldRule())->establishConnection('w'); $sql = array(); foreach ($applied_ids as $id) { $sql[] = qsprintf($conn_w, '(%s, %d)', $object->getPHID(), $id); } queryfx($conn_w, 'INSERT IGNORE INTO %T (phid, ruleID) VALUES %Q', HeraldRule::TABLE_RULE_APPLIED, implode(', ', $sql)); } } }
public function applyEffects(array $effects, HeraldObjectAdapter $object) { $this->transcript->setDryRun($object instanceof HeraldDryRunAdapter); $xscripts = $object->applyHeraldEffects($effects); foreach ($xscripts as $apply_xscript) { if (!$apply_xscript instanceof HeraldApplyTranscript) { throw new Exception("Heraldable must return HeraldApplyTranscripts from " . "applyHeraldEffect()."); } $this->transcript->addApplyTranscript($apply_xscript); } if (!$this->transcript->getDryRun()) { // Mark all the rules that have had their effects applied as having been // executed for the current object. $rule_ids = mpull($xscripts, 'getRuleID'); foreach ($rule_ids as $rule_id) { if (!$rule_id) { // Some apply transcripts are purely informational and not associated // with a rule, e.g. carryover emails from earlier revisions. continue; } HeraldRule::saveRuleApplied($rule_id, $object->getPHID()); } } }