@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Remove HeraldDryRunAdapter

Summary: Ref T2769. This isn't a real adapter and its methods are increasingly hacky messes. Make "dry run" a first-class concept on the HeraldEngine instead and remove the adapter.

Test Plan: Ran Herald via test console and via CLI.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2769

Differential Revision: https://secure.phabricator.com/D6693

+67 -95
-2
src/__phutil_library_map__.php
··· 604 604 'HeraldDAO' => 'applications/herald/storage/HeraldDAO.php', 605 605 'HeraldDeleteController' => 'applications/herald/controller/HeraldDeleteController.php', 606 606 'HeraldDifferentialRevisionAdapter' => 'applications/herald/adapter/HeraldDifferentialRevisionAdapter.php', 607 - 'HeraldDryRunAdapter' => 'applications/herald/adapter/HeraldDryRunAdapter.php', 608 607 'HeraldEditLogQuery' => 'applications/herald/query/HeraldEditLogQuery.php', 609 608 'HeraldEffect' => 'applications/herald/engine/HeraldEffect.php', 610 609 'HeraldEngine' => 'applications/herald/engine/HeraldEngine.php', ··· 2615 2614 'HeraldDAO' => 'PhabricatorLiskDAO', 2616 2615 'HeraldDeleteController' => 'HeraldController', 2617 2616 'HeraldDifferentialRevisionAdapter' => 'HeraldAdapter', 2618 - 'HeraldDryRunAdapter' => 'HeraldAdapter', 2619 2617 'HeraldEditLogQuery' => 'PhabricatorOffsetPagedQuery', 2620 2618 'HeraldInvalidActionException' => 'Exception', 2621 2619 'HeraldInvalidConditionException' => 'Exception',
-44
src/applications/herald/adapter/HeraldDryRunAdapter.php
··· 1 - <?php 2 - 3 - final class HeraldDryRunAdapter extends HeraldAdapter { 4 - 5 - public function getPHID() { 6 - return 0; 7 - } 8 - 9 - public function isEnabled() { 10 - return false; 11 - } 12 - 13 - public function getAdapterContentName() { 14 - return null; 15 - } 16 - 17 - public function getHeraldName() { 18 - return 'Dry Run'; 19 - } 20 - 21 - public function getHeraldField($field) { 22 - return null; 23 - } 24 - 25 - public function getFields() { 26 - return array(); 27 - } 28 - 29 - public function getActions($rule_type) { 30 - return array(); 31 - } 32 - 33 - public function applyHeraldEffects(array $effects) { 34 - assert_instances_of($effects, 'HeraldEffect'); 35 - $results = array(); 36 - foreach ($effects as $effect) { 37 - $results[] = new HeraldApplyTranscript( 38 - $effect, 39 - false, 40 - pht('This was a dry run, so no actions were actually taken.')); 41 - } 42 - return $results; 43 - } 44 - }
+4 -4
src/applications/herald/controller/HeraldTestConsoleController.php
··· 76 76 ->needValidateAuthors(true) 77 77 ->execute(); 78 78 79 - $engine = new HeraldEngine(); 80 - $effects = $engine->applyRules($rules, $adapter); 79 + $engine = id(new HeraldEngine()) 80 + ->setDryRun(true); 81 81 82 - $dry_run = new HeraldDryRunAdapter(); 83 - $engine->applyEffects($effects, $dry_run, $rules); 82 + $effects = $engine->applyRules($rules, $adapter); 83 + $engine->applyEffects($effects, $adapter, $rules); 84 84 85 85 $xscript = $engine->getTranscript(); 86 86
+62 -43
src/applications/herald/engine/HeraldEngine.php
··· 9 9 10 10 protected $fieldCache = array(); 11 11 protected $object = null; 12 + private $dryRun; 13 + 14 + public function setDryRun($dry_run) { 15 + $this->dryRun = $dry_run; 16 + return $this; 17 + } 18 + 19 + public function getDryRun() { 20 + return $this->dryRun; 21 + } 12 22 13 23 public function getRule($id) { 14 24 return idx($this->rules, $id); ··· 111 121 112 122 public function applyEffects( 113 123 array $effects, 114 - HeraldAdapter $object, 124 + HeraldAdapter $adapter, 115 125 array $rules) { 116 126 assert_instances_of($effects, 'HeraldEffect'); 117 127 assert_instances_of($rules, 'HeraldRule'); 118 128 119 - $this->transcript->setDryRun((int)($object instanceof HeraldDryRunAdapter)); 129 + $this->transcript->setDryRun((int)$this->getDryRun()); 120 130 121 - $xscripts = $object->applyHeraldEffects($effects); 122 - foreach ($xscripts as $apply_xscript) { 123 - if (!($apply_xscript instanceof HeraldApplyTranscript)) { 124 - throw new Exception( 125 - "Heraldable must return HeraldApplyTranscripts from ". 126 - "applyHeraldEffect()."); 131 + if ($this->getDryRun()) { 132 + $xscripts = array(); 133 + foreach ($effects as $effect) { 134 + $xscripts[] = new HeraldApplyTranscript( 135 + $effect, 136 + false, 137 + pht('This was a dry run, so no actions were actually taken.')); 127 138 } 139 + } else { 140 + $xscripts = $adapter->applyHeraldEffects($effects); 141 + } 142 + 143 + assert_instances_of($xscripts, 'HeraldApplyTranscript'); 144 + foreach ($xscripts as $apply_xscript) { 128 145 $this->transcript->addApplyTranscript($apply_xscript); 129 146 } 130 147 131 - if (!$this->transcript->getDryRun()) { 148 + // For dry runs, don't mark the rule as having applied to the object. 149 + if ($this->getDryRun()) { 150 + return; 151 + } 132 152 133 - $rules = mpull($rules, null, 'getID'); 134 - $applied_ids = array(); 135 - $first_policy = HeraldRepetitionPolicyConfig::toInt( 136 - HeraldRepetitionPolicyConfig::FIRST); 153 + $rules = mpull($rules, null, 'getID'); 154 + $applied_ids = array(); 155 + $first_policy = HeraldRepetitionPolicyConfig::toInt( 156 + HeraldRepetitionPolicyConfig::FIRST); 137 157 138 - // Mark all the rules that have had their effects applied as having been 139 - // executed for the current object. 140 - $rule_ids = mpull($xscripts, 'getRuleID'); 158 + // Mark all the rules that have had their effects applied as having been 159 + // executed for the current object. 160 + $rule_ids = mpull($xscripts, 'getRuleID'); 141 161 142 - foreach ($rule_ids as $rule_id) { 143 - if (!$rule_id) { 144 - // Some apply transcripts are purely informational and not associated 145 - // with a rule, e.g. carryover emails from earlier revisions. 146 - continue; 147 - } 162 + foreach ($rule_ids as $rule_id) { 163 + if (!$rule_id) { 164 + // Some apply transcripts are purely informational and not associated 165 + // with a rule, e.g. carryover emails from earlier revisions. 166 + continue; 167 + } 148 168 149 - $rule = idx($rules, $rule_id); 150 - if (!$rule) { 151 - continue; 152 - } 169 + $rule = idx($rules, $rule_id); 170 + if (!$rule) { 171 + continue; 172 + } 153 173 154 - if ($rule->getRepetitionPolicy() == $first_policy) { 155 - $applied_ids[] = $rule_id; 156 - } 174 + if ($rule->getRepetitionPolicy() == $first_policy) { 175 + $applied_ids[] = $rule_id; 157 176 } 177 + } 158 178 159 - if ($applied_ids) { 160 - $conn_w = id(new HeraldRule())->establishConnection('w'); 161 - $sql = array(); 162 - foreach ($applied_ids as $id) { 163 - $sql[] = qsprintf( 164 - $conn_w, 165 - '(%s, %d)', 166 - $object->getPHID(), 167 - $id); 168 - } 169 - queryfx( 179 + if ($applied_ids) { 180 + $conn_w = id(new HeraldRule())->establishConnection('w'); 181 + $sql = array(); 182 + foreach ($applied_ids as $id) { 183 + $sql[] = qsprintf( 170 184 $conn_w, 171 - 'INSERT IGNORE INTO %T (phid, ruleID) VALUES %Q', 172 - HeraldRule::TABLE_RULE_APPLIED, 173 - implode(', ', $sql)); 185 + '(%s, %d)', 186 + $adapter->getPHID(), 187 + $id); 174 188 } 189 + queryfx( 190 + $conn_w, 191 + 'INSERT IGNORE INTO %T (phid, ruleID) VALUES %Q', 192 + HeraldRule::TABLE_RULE_APPLIED, 193 + implode(', ', $sql)); 175 194 } 176 195 } 177 196
+1 -2
src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php
··· 38 38 39 39 $effects = $engine->applyRules($rules, $adapter); 40 40 $engine->applyEffects($effects, $adapter, $rules); 41 + $xscript = $engine->getTranscript(); 41 42 42 43 $audit_phids = $adapter->getAuditMap(); 43 44 if ($audit_phids) { ··· 62 63 if (!$email_phids) { 63 64 return; 64 65 } 65 - 66 - $xscript = $engine->getTranscript(); 67 66 68 67 $revision = $adapter->loadDifferentialRevision(); 69 68 if ($revision) {