diff --git a/src/applications/herald/adapter/HeraldAdapter.php b/src/applications/herald/adapter/HeraldAdapter.php index fe047ae428..a478284231 100644 --- a/src/applications/herald/adapter/HeraldAdapter.php +++ b/src/applications/herald/adapter/HeraldAdapter.php @@ -243,6 +243,22 @@ abstract class HeraldAdapter { return $this->queuedTransactions; } + protected function newTransaction() { + $object = $this->getObject(); + + if (!($object instanceof PhabricatorApplicationTransactionInterface)) { + throw new Exception( + pht( + 'Unable to build a new transaction for adapter object; it does '. + 'not implement "%s".', + 'PhabricatorApplicationTransactionInterface')); + } + + return $object->getApplicationTransactionTemplate(); + } + + + /** * NOTE: You generally should not override this; it exists to support legacy @@ -1482,7 +1498,21 @@ abstract class HeraldAdapter { protected function applyStandardEffect(HeraldEffect $effect) { $action = $effect->getAction(); + $rule_type = $effect->getRule()->getRuleType(); + $supported = $this->getActions($rule_type); + $supported = array_fuse($supported); + if (empty($supported[$action])) { + throw new Exception( + pht( + 'Adapter "%s" does not support action "%s" for rule type "%s".', + get_class($this), + $action, + $rule_type)); + } + switch ($action) { + case self::ACTION_ADD_PROJECTS: + return $this->applyProjectsEffect($effect); case self::ACTION_FLAG: return $this->applyFlagEffect($effect); case self::ACTION_EMAIL: @@ -1504,6 +1534,32 @@ abstract class HeraldAdapter { } + /** + * @task apply + */ + private function applyProjectsEffect(HeraldEffect $effect) { + + $kind = '+'; + + $project_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST; + $project_phids = $effect->getTarget(); + $xaction = $this->newTransaction() + ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) + ->setMetadataValue('edge:type', $project_type) + ->setNewValue( + array( + $kind => array_fuse($project_phids), + )); + + $this->queueTransaction($xaction); + + return new HeraldApplyTranscript( + $effect, + true, + pht('Added projects.')); + } + + /** * @task apply */ diff --git a/src/applications/herald/adapter/HeraldManiphestTaskAdapter.php b/src/applications/herald/adapter/HeraldManiphestTaskAdapter.php index e49aa73f67..f25d5fa296 100644 --- a/src/applications/herald/adapter/HeraldManiphestTaskAdapter.php +++ b/src/applications/herald/adapter/HeraldManiphestTaskAdapter.php @@ -5,7 +5,6 @@ final class HeraldManiphestTaskAdapter extends HeraldAdapter { private $task; private $ccPHIDs = array(); private $assignPHID; - private $projectPHIDs = array(); public function getAdapterApplicationClass() { return 'PhabricatorManiphestApplication'; @@ -61,14 +60,6 @@ final class HeraldManiphestTaskAdapter extends HeraldAdapter { return $this->assignPHID; } - public function setProjectPHIDs(array $project_phids) { - $this->projectPHIDs = $project_phids; - return $this; - } - public function getProjectPHIDs() { - return $this->projectPHIDs; - } - public function getAdapterContentName() { return pht('Maniphest Tasks'); } @@ -181,15 +172,6 @@ final class HeraldManiphestTaskAdapter extends HeraldAdapter { true, pht('Assigned task.')); break; - case self::ACTION_ADD_PROJECTS: - foreach ($effect->getTarget() as $phid) { - $this->projectPHIDs[] = $phid; - } - $result[] = new HeraldApplyTranscript( - $effect, - true, - pht('Added projects.')); - break; default: $result[] = $this->applyStandardEffect($effect); break; diff --git a/src/applications/maniphest/editor/ManiphestTransactionEditor.php b/src/applications/maniphest/editor/ManiphestTransactionEditor.php index 54f75adbb8..0b733baf27 100644 --- a/src/applications/maniphest/editor/ManiphestTransactionEditor.php +++ b/src/applications/maniphest/editor/ManiphestTransactionEditor.php @@ -525,18 +525,6 @@ final class ManiphestTransactionEditor ->setNewValue($assign_phid); } - $project_phids = $adapter->getProjectPHIDs(); - if ($project_phids) { - $project_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST; - $xactions[] = id(new ManiphestTransaction()) - ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) - ->setMetadataValue('edge:type', $project_type) - ->setNewValue( - array( - '+' => array_fuse($project_phids), - )); - } - return $xactions; }