@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.

Attach HeraldRules to HeraldEffects

Summary:
Ref T7731. For no particular reason, we currently put `ruleID` and `rulePHID` on `HeraldEffect` objects.

Pretty much all callers need the `HeraldRule` objects instead, and some go to great lengths to get them.

Just attach the `Rule` objects.

Test Plan: Will test thoroughly after next-ish changeset.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T7731

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

+28 -52
+3 -8
src/applications/differential/editor/DifferentialDiffEditor.php
··· 145 145 } 146 146 147 147 if ($blocking_effect) { 148 - $rule = idx($rules, $effect->getRuleID()); 149 - if ($rule && strlen($rule->getName())) { 150 - $rule_name = $rule->getName(); 151 - } else { 152 - $rule_name = pht('Unnamed Herald Rule'); 153 - } 148 + $rule = $blocking_effect->getRule(); 154 149 155 150 $message = $effect->getTarget(); 156 151 if (!strlen($message)) { ··· 164 159 "Creation of this diff was rejected by Herald rule %s.\n". 165 160 " Rule: %s\n". 166 161 "Reason: %s", 167 - 'H'.$effect->getRuleID(), 168 - $rule_name, 162 + $rule->getMonogram(), 163 + $rule->getName(), 169 164 $message)); 170 165 } 171 166 break;
+5 -11
src/applications/diffusion/engine/DiffusionCommitHookEngine.php
··· 337 337 } 338 338 339 339 if ($blocking_effect) { 340 + $rule = $blocking_effect->getRule(); 341 + 340 342 $this->rejectCode = PhabricatorRepositoryPushLog::REJECT_HERALD; 341 - $this->rejectDetails = $blocking_effect->getRulePHID(); 343 + $this->rejectDetails = $rule->getPHID(); 342 344 343 345 $message = $blocking_effect->getTarget(); 344 346 if (!strlen($message)) { 345 347 $message = pht('(None.)'); 346 348 } 347 349 348 - $rules = mpull($rules, null, 'getID'); 349 - $rule = idx($rules, $effect->getRuleID()); 350 - if ($rule && strlen($rule->getName())) { 351 - $rule_name = $rule->getName(); 352 - } else { 353 - $rule_name = pht('Unnamed Herald Rule'); 354 - } 355 - 356 350 $blocked_ref_name = coalesce( 357 351 $blocked_update->getRefName(), 358 352 $blocked_update->getRefNewShort()); ··· 364 358 "Change: %s\n". 365 359 " Rule: %s\n". 366 360 "Reason: %s", 367 - 'H'.$blocking_effect->getRuleID(), 361 + $rule->getMonogram(), 368 362 $blocked_name, 369 - $rule_name, 363 + $rule->getName(), 370 364 $message)); 371 365 } 372 366 }
+2 -5
src/applications/herald/adapter/HeraldAdapter.php
··· 999 999 public static function applyFlagEffect(HeraldEffect $effect, $phid) { 1000 1000 $color = $effect->getTarget(); 1001 1001 1002 - // TODO: Silly that we need to load this again here. 1003 - $rule = id(new HeraldRule())->load($effect->getRuleID()); 1004 - $user = id(new PhabricatorUser())->loadOneWhere( 1005 - 'phid = %s', 1006 - $rule->getAuthorPHID()); 1002 + $rule = $effect->getRule(); 1003 + $user = $rule->getAuthor(); 1007 1004 1008 1005 $flag = PhabricatorFlagQuery::loadUserFlag($user, $phid); 1009 1006 if ($flag) {
+2 -2
src/applications/herald/adapter/HeraldCommitAdapter.php
··· 501 501 if (empty($this->addCCPHIDs[$phid])) { 502 502 $this->addCCPHIDs[$phid] = array(); 503 503 } 504 - $this->addCCPHIDs[$phid][] = $effect->getRuleID(); 504 + $this->addCCPHIDs[$phid][] = $effect->getRule()->getID(); 505 505 } 506 506 $result[] = new HeraldApplyTranscript( 507 507 $effect, ··· 513 513 if (empty($this->auditMap[$phid])) { 514 514 $this->auditMap[$phid] = array(); 515 515 } 516 - $this->auditMap[$phid][] = $effect->getRuleID(); 516 + $this->auditMap[$phid][] = $effect->getRule()->getID(); 517 517 } 518 518 $result[] = new HeraldApplyTranscript( 519 519 $effect,
+5 -17
src/applications/herald/engine/HeraldEffect.php
··· 5 5 private $objectPHID; 6 6 private $action; 7 7 private $target; 8 - 9 - private $ruleID; 10 - private $rulePHID; 11 - 8 + private $rule; 12 9 private $reason; 13 10 14 11 public function setObjectPHID($object_phid) { ··· 38 35 return $this->target; 39 36 } 40 37 41 - public function setRuleID($rule_id) { 42 - $this->ruleID = $rule_id; 38 + public function setRule(HeraldRule $rule) { 39 + $this->rule = $rule; 43 40 return $this; 44 41 } 45 42 46 - public function getRuleID() { 47 - return $this->ruleID; 48 - } 49 - 50 - public function setRulePHID($rule_phid) { 51 - $this->rulePHID = $rule_phid; 52 - return $this; 53 - } 54 - 55 - public function getRulePHID() { 56 - return $this->rulePHID; 43 + public function getRule() { 44 + return $this->rule; 57 45 } 58 46 59 47 public function setReason($reason) {
+6 -8
src/applications/herald/engine/HeraldEngine.php
··· 368 368 369 369 $effects = array(); 370 370 foreach ($rule->getActions() as $action) { 371 - $effect = new HeraldEffect(); 372 - $effect->setObjectPHID($object->getPHID()); 373 - $effect->setAction($action->getAction()); 374 - $effect->setTarget($action->getTarget()); 375 - 376 - $effect->setRuleID($rule->getID()); 377 - $effect->setRulePHID($rule->getPHID()); 371 + $effect = id(new HeraldEffect()) 372 + ->setObjectPHID($object->getPHID()) 373 + ->setAction($action->getAction()) 374 + ->setTarget($action->getTarget()) 375 + ->setRule($rule); 378 376 379 377 $name = $rule->getName(); 380 - $id = $rule->getID(); 378 + $id = $rule->getID(); 381 379 $effect->setReason( 382 380 pht( 383 381 'Conditions were met for %s',
+4
src/applications/herald/storage/HeraldRule.php
··· 265 265 return sprintf('~%d%010d', $type_order, $this->getID()); 266 266 } 267 267 268 + public function getMonogram() { 269 + return 'H'.$this->getID(); 270 + } 271 + 268 272 269 273 /* -( PhabricatorApplicationTransactionInterface )------------------------- */ 270 274
+1 -1
src/applications/herald/storage/transcript/HeraldApplyTranscript.php
··· 16 16 17 17 $this->setAction($effect->getAction()); 18 18 $this->setTarget($effect->getTarget()); 19 - $this->setRuleID($effect->getRuleID()); 19 + $this->setRuleID($effect->getRule()->getID()); 20 20 $this->setReason($effect->getReason()); 21 21 $this->setApplied($applied); 22 22 $this->setAppliedReason($reason);