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

Lift handling of Herald "email" effect to Adapter

Summary:
Ref T7731. Every adapter subclass currently implements this effect in an essentially identical way.

Some day far from now the effects will be modular and this mess will vanish completely, but reduce its sprawl for now.

Test Plan: I'll test this thoroughly at the end of the change sequence since writing rules is a pain.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T7731

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

+30 -66
+1 -2
src/applications/differential/editor/DifferentialTransactionEditor.php
··· 1731 1731 } 1732 1732 1733 1733 // Save extra email PHIDs for later. 1734 - $email_phids = $adapter->getEmailPHIDsAddedByHerald(); 1735 - $this->heraldEmailPHIDs = array_keys($email_phids); 1734 + $this->heraldEmailPHIDs = $adapter->getEmailPHIDs(); 1736 1735 1737 1736 // Apply build plans. 1738 1737 HarbormasterBuildable::applyBuildPlans(
+1 -12
src/applications/diffusion/herald/HeraldPreCommitAdapter.php
··· 4 4 5 5 private $log; 6 6 private $hookEngine; 7 - private $emailPHIDs = array(); 8 7 9 8 public function setPushLog(PhabricatorRepositoryPushLog $log) { 10 9 $this->log = $log; ··· 26 25 27 26 public function getObject() { 28 27 return $this->log; 29 - } 30 - 31 - public function getEmailPHIDs() { 32 - return array_values($this->emailPHIDs); 33 28 } 34 29 35 30 public function supportsRuleType($rule_type) { ··· 107 102 pht('Did nothing.')); 108 103 break; 109 104 case self::ACTION_EMAIL: 110 - foreach ($effect->getTarget() as $phid) { 111 - $this->emailPHIDs[$phid] = $phid; 112 - } 113 - $result[] = new HeraldApplyTranscript( 114 - $effect, 115 - true, 116 - pht('Added mailable to mail targets.')); 105 + $result[] = $this->applyEmailEffect($effect); 117 106 break; 118 107 case self::ACTION_BLOCK: 119 108 $result[] = new HeraldApplyTranscript(
+17
src/applications/herald/adapter/HeraldAdapter.php
··· 109 109 private $customFields = false; 110 110 private $customActions = null; 111 111 private $queuedTransactions = array(); 112 + private $emailPHIDs = array(); 113 + 114 + public function getEmailPHIDs() { 115 + return array_values($this->emailPHIDs); 116 + } 112 117 113 118 public function getCustomActions() { 114 119 if ($this->customActions === null) { ··· 1030 1035 $effect, 1031 1036 true, 1032 1037 pht('Added flag.')); 1038 + } 1039 + 1040 + protected function applyEmailEffect(HeraldEffect $effect) { 1041 + 1042 + foreach ($effect->getTarget() as $phid) { 1043 + $this->emailPHIDs[$phid] = $phid; 1044 + } 1045 + 1046 + return new HeraldApplyTranscript( 1047 + $effect, 1048 + true, 1049 + pht('Added mailable to mail targets.')); 1033 1050 } 1034 1051 1035 1052 public static function getAllAdapters() {
+1 -12
src/applications/herald/adapter/HeraldCommitAdapter.php
··· 13 13 protected $commitData; 14 14 private $commitDiff; 15 15 16 - protected $emailPHIDs = array(); 17 16 protected $addCCPHIDs = array(); 18 17 protected $auditMap = array(); 19 18 protected $buildPlans = array(); ··· 215 214 216 215 public function getPHID() { 217 216 return $this->commit->getPHID(); 218 - } 219 - 220 - public function getEmailPHIDs() { 221 - return array_keys($this->emailPHIDs); 222 217 } 223 218 224 219 public function getAddCCMap() { ··· 499 494 pht('Great success at doing nothing.')); 500 495 break; 501 496 case self::ACTION_EMAIL: 502 - foreach ($effect->getTarget() as $phid) { 503 - $this->emailPHIDs[$phid] = true; 504 - } 505 - $result[] = new HeraldApplyTranscript( 506 - $effect, 507 - true, 508 - pht('Added address to email targets.')); 497 + $result[] = $this->applyEmailEffect($effect); 509 498 break; 510 499 case self::ACTION_ADD_CC: 511 500 foreach ($effect->getTarget() as $phid) {
+7 -15
src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php
··· 11 11 12 12 protected $newCCs = array(); 13 13 protected $remCCs = array(); 14 - protected $emailPHIDs = array(); 15 14 protected $addReviewerPHIDs = array(); 16 15 protected $blockingReviewerPHIDs = array(); 17 16 protected $buildPlans = array(); ··· 129 128 130 129 public function getCCsRemovedByHerald() { 131 130 return $this->remCCs; 132 - } 133 - 134 - public function getEmailPHIDsAddedByHerald() { 135 - return $this->emailPHIDs; 136 131 } 137 132 138 133 public function getReviewersAddedByHerald() { ··· 333 328 $this->revision->getPHID()); 334 329 break; 335 330 case self::ACTION_EMAIL: 331 + $result[] = $this->applyEmailEffect($effect); 332 + break; 336 333 case self::ACTION_ADD_CC: 337 - $op = ($action == self::ACTION_EMAIL) ? 'email' : 'CC'; 338 334 $base_target = $effect->getTarget(); 339 335 $forbidden = array(); 340 336 foreach ($base_target as $key => $fbid) { ··· 342 338 $forbidden[] = $fbid; 343 339 unset($base_target[$key]); 344 340 } else { 345 - if ($action == self::ACTION_EMAIL) { 346 - $this->emailPHIDs[$fbid] = true; 347 - } else { 348 - $this->newCCs[$fbid] = true; 349 - } 341 + $this->newCCs[$fbid] = true; 350 342 } 351 343 } 352 344 ··· 358 350 $result[] = new HeraldApplyTranscript( 359 351 $effect, 360 352 true, 361 - pht('Added these addresses to %s list. '. 362 - 'Others could not be added.', $op)); 353 + pht('Added these addresses to CC list. '. 354 + 'Others could not be added.')); 363 355 } 364 356 $result[] = new HeraldApplyTranscript( 365 357 $failed, 366 358 false, 367 - pht('%s forbidden, these addresses have unsubscribed.', $op)); 359 + pht('CC forbidden, these addresses have unsubscribed.')); 368 360 } else { 369 361 $result[] = new HeraldApplyTranscript( 370 362 $effect, 371 363 true, 372 - pht('Added addresses to %s list.', $op)); 364 + pht('Added addresses to CC list.')); 373 365 } 374 366 break; 375 367 case self::ACTION_REMOVE_CC:
+1 -12
src/applications/herald/adapter/HeraldManiphestTaskAdapter.php
··· 6 6 private $ccPHIDs = array(); 7 7 private $assignPHID; 8 8 private $projectPHIDs = array(); 9 - private $emailPHIDs = array(); 10 - 11 - public function getEmailPHIDs() { 12 - return $this->emailPHIDs; 13 - } 14 9 15 10 public function getAdapterApplicationClass() { 16 11 return 'PhabricatorManiphestApplication'; ··· 178 173 pht('Added addresses to cc list.')); 179 174 break; 180 175 case self::ACTION_EMAIL: 181 - foreach ($effect->getTarget() as $phid) { 182 - $this->emailPHIDs[] = $phid; 183 - } 184 - $result[] = new HeraldApplyTranscript( 185 - $effect, 186 - true, 187 - pht('Added addresses to email list.')); 176 + $result[] = $this->applyEmailEffect($effect); 188 177 break; 189 178 case self::ACTION_FLAG: 190 179 $result[] = parent::applyFlagEffect(
+2 -13
src/applications/phriction/herald/PhrictionDocumentHeraldAdapter.php
··· 4 4 5 5 private $document; 6 6 private $ccPHIDs = array(); 7 - private $emailPHIDs = array(); 8 7 9 8 public function getAdapterApplicationClass() { 10 9 return 'PhabricatorPhrictionApplication'; ··· 30 29 $this->ccPHIDs = $cc_phids; 31 30 return $this; 32 31 } 32 + 33 33 public function getCcPHIDs() { 34 34 return $this->ccPHIDs; 35 35 } 36 - 37 - public function getEmailPHIDs() { 38 - return $this->emailPHIDs; 39 - } 40 - 41 36 42 37 public function getAdapterContentName() { 43 38 return pht('Phriction Documents'); ··· 143 138 $this->getDocument()->getPHID()); 144 139 break; 145 140 case self::ACTION_EMAIL: 146 - foreach ($effect->getTarget() as $phid) { 147 - $this->emailPHIDs[] = $phid; 148 - } 149 - $result[] = new HeraldApplyTranscript( 150 - $effect, 151 - true, 152 - pht('Added addresses to email list.')); 141 + $result[] = $this->applyEmailEffect($effect); 153 142 break; 154 143 default: 155 144 $custom_result = parent::handleCustomHeraldEffect($effect);