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
This commit is contained in:
epriestley
2015-04-06 10:00:35 -07:00
parent e0edb0797c
commit a40748a46c
7 changed files with 30 additions and 66 deletions

View File

@@ -1731,8 +1731,7 @@ final class DifferentialTransactionEditor
} }
// Save extra email PHIDs for later. // Save extra email PHIDs for later.
$email_phids = $adapter->getEmailPHIDsAddedByHerald(); $this->heraldEmailPHIDs = $adapter->getEmailPHIDs();
$this->heraldEmailPHIDs = array_keys($email_phids);
// Apply build plans. // Apply build plans.
HarbormasterBuildable::applyBuildPlans( HarbormasterBuildable::applyBuildPlans(

View File

@@ -4,7 +4,6 @@ abstract class HeraldPreCommitAdapter extends HeraldAdapter {
private $log; private $log;
private $hookEngine; private $hookEngine;
private $emailPHIDs = array();
public function setPushLog(PhabricatorRepositoryPushLog $log) { public function setPushLog(PhabricatorRepositoryPushLog $log) {
$this->log = $log; $this->log = $log;
@@ -28,10 +27,6 @@ abstract class HeraldPreCommitAdapter extends HeraldAdapter {
return $this->log; return $this->log;
} }
public function getEmailPHIDs() {
return array_values($this->emailPHIDs);
}
public function supportsRuleType($rule_type) { public function supportsRuleType($rule_type) {
switch ($rule_type) { switch ($rule_type) {
case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL: case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL:
@@ -107,13 +102,7 @@ abstract class HeraldPreCommitAdapter extends HeraldAdapter {
pht('Did nothing.')); pht('Did nothing.'));
break; break;
case self::ACTION_EMAIL: case self::ACTION_EMAIL:
foreach ($effect->getTarget() as $phid) { $result[] = $this->applyEmailEffect($effect);
$this->emailPHIDs[$phid] = $phid;
}
$result[] = new HeraldApplyTranscript(
$effect,
true,
pht('Added mailable to mail targets.'));
break; break;
case self::ACTION_BLOCK: case self::ACTION_BLOCK:
$result[] = new HeraldApplyTranscript( $result[] = new HeraldApplyTranscript(

View File

@@ -109,6 +109,11 @@ abstract class HeraldAdapter {
private $customFields = false; private $customFields = false;
private $customActions = null; private $customActions = null;
private $queuedTransactions = array(); private $queuedTransactions = array();
private $emailPHIDs = array();
public function getEmailPHIDs() {
return array_values($this->emailPHIDs);
}
public function getCustomActions() { public function getCustomActions() {
if ($this->customActions === null) { if ($this->customActions === null) {
@@ -1032,6 +1037,18 @@ abstract class HeraldAdapter {
pht('Added flag.')); pht('Added flag.'));
} }
protected function applyEmailEffect(HeraldEffect $effect) {
foreach ($effect->getTarget() as $phid) {
$this->emailPHIDs[$phid] = $phid;
}
return new HeraldApplyTranscript(
$effect,
true,
pht('Added mailable to mail targets.'));
}
public static function getAllAdapters() { public static function getAllAdapters() {
static $adapters; static $adapters;
if (!$adapters) { if (!$adapters) {

View File

@@ -13,7 +13,6 @@ final class HeraldCommitAdapter extends HeraldAdapter {
protected $commitData; protected $commitData;
private $commitDiff; private $commitDiff;
protected $emailPHIDs = array();
protected $addCCPHIDs = array(); protected $addCCPHIDs = array();
protected $auditMap = array(); protected $auditMap = array();
protected $buildPlans = array(); protected $buildPlans = array();
@@ -217,10 +216,6 @@ final class HeraldCommitAdapter extends HeraldAdapter {
return $this->commit->getPHID(); return $this->commit->getPHID();
} }
public function getEmailPHIDs() {
return array_keys($this->emailPHIDs);
}
public function getAddCCMap() { public function getAddCCMap() {
return $this->addCCPHIDs; return $this->addCCPHIDs;
} }
@@ -499,13 +494,7 @@ final class HeraldCommitAdapter extends HeraldAdapter {
pht('Great success at doing nothing.')); pht('Great success at doing nothing.'));
break; break;
case self::ACTION_EMAIL: case self::ACTION_EMAIL:
foreach ($effect->getTarget() as $phid) { $result[] = $this->applyEmailEffect($effect);
$this->emailPHIDs[$phid] = true;
}
$result[] = new HeraldApplyTranscript(
$effect,
true,
pht('Added address to email targets.'));
break; break;
case self::ACTION_ADD_CC: case self::ACTION_ADD_CC:
foreach ($effect->getTarget() as $phid) { foreach ($effect->getTarget() as $phid) {

View File

@@ -11,7 +11,6 @@ final class HeraldDifferentialRevisionAdapter
protected $newCCs = array(); protected $newCCs = array();
protected $remCCs = array(); protected $remCCs = array();
protected $emailPHIDs = array();
protected $addReviewerPHIDs = array(); protected $addReviewerPHIDs = array();
protected $blockingReviewerPHIDs = array(); protected $blockingReviewerPHIDs = array();
protected $buildPlans = array(); protected $buildPlans = array();
@@ -131,10 +130,6 @@ final class HeraldDifferentialRevisionAdapter
return $this->remCCs; return $this->remCCs;
} }
public function getEmailPHIDsAddedByHerald() {
return $this->emailPHIDs;
}
public function getReviewersAddedByHerald() { public function getReviewersAddedByHerald() {
return $this->addReviewerPHIDs; return $this->addReviewerPHIDs;
} }
@@ -333,8 +328,9 @@ final class HeraldDifferentialRevisionAdapter
$this->revision->getPHID()); $this->revision->getPHID());
break; break;
case self::ACTION_EMAIL: case self::ACTION_EMAIL:
$result[] = $this->applyEmailEffect($effect);
break;
case self::ACTION_ADD_CC: case self::ACTION_ADD_CC:
$op = ($action == self::ACTION_EMAIL) ? 'email' : 'CC';
$base_target = $effect->getTarget(); $base_target = $effect->getTarget();
$forbidden = array(); $forbidden = array();
foreach ($base_target as $key => $fbid) { foreach ($base_target as $key => $fbid) {
@@ -342,11 +338,7 @@ final class HeraldDifferentialRevisionAdapter
$forbidden[] = $fbid; $forbidden[] = $fbid;
unset($base_target[$key]); unset($base_target[$key]);
} else { } else {
if ($action == self::ACTION_EMAIL) { $this->newCCs[$fbid] = true;
$this->emailPHIDs[$fbid] = true;
} else {
$this->newCCs[$fbid] = true;
}
} }
} }
@@ -358,18 +350,18 @@ final class HeraldDifferentialRevisionAdapter
$result[] = new HeraldApplyTranscript( $result[] = new HeraldApplyTranscript(
$effect, $effect,
true, true,
pht('Added these addresses to %s list. '. pht('Added these addresses to CC list. '.
'Others could not be added.', $op)); 'Others could not be added.'));
} }
$result[] = new HeraldApplyTranscript( $result[] = new HeraldApplyTranscript(
$failed, $failed,
false, false,
pht('%s forbidden, these addresses have unsubscribed.', $op)); pht('CC forbidden, these addresses have unsubscribed.'));
} else { } else {
$result[] = new HeraldApplyTranscript( $result[] = new HeraldApplyTranscript(
$effect, $effect,
true, true,
pht('Added addresses to %s list.', $op)); pht('Added addresses to CC list.'));
} }
break; break;
case self::ACTION_REMOVE_CC: case self::ACTION_REMOVE_CC:

View File

@@ -6,11 +6,6 @@ final class HeraldManiphestTaskAdapter extends HeraldAdapter {
private $ccPHIDs = array(); private $ccPHIDs = array();
private $assignPHID; private $assignPHID;
private $projectPHIDs = array(); private $projectPHIDs = array();
private $emailPHIDs = array();
public function getEmailPHIDs() {
return $this->emailPHIDs;
}
public function getAdapterApplicationClass() { public function getAdapterApplicationClass() {
return 'PhabricatorManiphestApplication'; return 'PhabricatorManiphestApplication';
@@ -178,13 +173,7 @@ final class HeraldManiphestTaskAdapter extends HeraldAdapter {
pht('Added addresses to cc list.')); pht('Added addresses to cc list.'));
break; break;
case self::ACTION_EMAIL: case self::ACTION_EMAIL:
foreach ($effect->getTarget() as $phid) { $result[] = $this->applyEmailEffect($effect);
$this->emailPHIDs[] = $phid;
}
$result[] = new HeraldApplyTranscript(
$effect,
true,
pht('Added addresses to email list.'));
break; break;
case self::ACTION_FLAG: case self::ACTION_FLAG:
$result[] = parent::applyFlagEffect( $result[] = parent::applyFlagEffect(

View File

@@ -4,7 +4,6 @@ final class PhrictionDocumentHeraldAdapter extends HeraldAdapter {
private $document; private $document;
private $ccPHIDs = array(); private $ccPHIDs = array();
private $emailPHIDs = array();
public function getAdapterApplicationClass() { public function getAdapterApplicationClass() {
return 'PhabricatorPhrictionApplication'; return 'PhabricatorPhrictionApplication';
@@ -30,15 +29,11 @@ final class PhrictionDocumentHeraldAdapter extends HeraldAdapter {
$this->ccPHIDs = $cc_phids; $this->ccPHIDs = $cc_phids;
return $this; return $this;
} }
public function getCcPHIDs() { public function getCcPHIDs() {
return $this->ccPHIDs; return $this->ccPHIDs;
} }
public function getEmailPHIDs() {
return $this->emailPHIDs;
}
public function getAdapterContentName() { public function getAdapterContentName() {
return pht('Phriction Documents'); return pht('Phriction Documents');
} }
@@ -143,13 +138,7 @@ final class PhrictionDocumentHeraldAdapter extends HeraldAdapter {
$this->getDocument()->getPHID()); $this->getDocument()->getPHID());
break; break;
case self::ACTION_EMAIL: case self::ACTION_EMAIL:
foreach ($effect->getTarget() as $phid) { $result[] = $this->applyEmailEffect($effect);
$this->emailPHIDs[] = $phid;
}
$result[] = new HeraldApplyTranscript(
$effect,
true,
pht('Added addresses to email list.'));
break; break;
default: default:
$custom_result = parent::handleCustomHeraldEffect($effect); $custom_result = parent::handleCustomHeraldEffect($effect);