mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-21 13:00:56 +01:00
Make adding projects a standard Herald effect
Summary: Ref T7849. Lift project actions into the base class. Some day they'll be fully modular. Test Plan: - Wrote an "add projects" Herald rule. - Edited Maniphest tasks. - Got projects added. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T7849 Differential Revision: https://secure.phabricator.com/D12503
This commit is contained in:
parent
4e47e3a116
commit
501630d931
3 changed files with 56 additions and 30 deletions
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue