2013-09-25 20:50:15 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group herald
|
|
|
|
*/
|
|
|
|
final class HeraldManiphestTaskAdapter extends HeraldAdapter {
|
|
|
|
|
|
|
|
private $task;
|
|
|
|
private $ccPHIDs = array();
|
2013-09-27 00:04:55 +02:00
|
|
|
private $assignPHID;
|
|
|
|
private $projectPHIDs = array();
|
2013-09-25 20:50:15 +02:00
|
|
|
|
2013-10-05 00:15:48 +02:00
|
|
|
public function getAdapterApplicationClass() {
|
|
|
|
return 'PhabricatorApplicationManiphest';
|
|
|
|
}
|
|
|
|
|
2013-12-27 22:16:33 +01:00
|
|
|
public function getAdapterContentDescription() {
|
|
|
|
return pht(
|
|
|
|
'React to tasks being created or updated.');
|
|
|
|
}
|
|
|
|
|
2013-12-31 01:48:07 +01:00
|
|
|
public function supportsRuleType($rule_type) {
|
|
|
|
switch ($rule_type) {
|
|
|
|
case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL:
|
|
|
|
case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL:
|
|
|
|
return true;
|
|
|
|
case HeraldRuleTypeConfig::RULE_TYPE_OBJECT:
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-25 20:50:15 +02:00
|
|
|
public function setTask(ManiphestTask $task) {
|
|
|
|
$this->task = $task;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
public function getTask() {
|
|
|
|
return $this->task;
|
|
|
|
}
|
|
|
|
|
2013-10-05 21:55:34 +02:00
|
|
|
public function getObject() {
|
|
|
|
return $this->task;
|
|
|
|
}
|
|
|
|
|
2013-09-25 20:50:15 +02:00
|
|
|
private function setCcPHIDs(array $cc_phids) {
|
|
|
|
$this->ccPHIDs = $cc_phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
public function getCcPHIDs() {
|
|
|
|
return $this->ccPHIDs;
|
|
|
|
}
|
|
|
|
|
2013-09-27 00:04:55 +02:00
|
|
|
public function setAssignPHID($assign_phid) {
|
|
|
|
$this->assignPHID = $assign_phid;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
public function getAssignPHID() {
|
|
|
|
return $this->assignPHID;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setProjectPHIDs(array $project_phids) {
|
|
|
|
$this->projectPHIDs = $project_phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
public function getProjectPHIDs() {
|
|
|
|
return $this->projectPHIDs;
|
|
|
|
}
|
|
|
|
|
2013-09-25 20:50:15 +02:00
|
|
|
public function getAdapterContentName() {
|
|
|
|
return pht('Maniphest Tasks');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFields() {
|
2013-10-04 02:53:12 +02:00
|
|
|
return array_merge(
|
|
|
|
array(
|
|
|
|
self::FIELD_TITLE,
|
|
|
|
self::FIELD_BODY,
|
|
|
|
self::FIELD_AUTHOR,
|
2013-12-22 17:47:31 +01:00
|
|
|
self::FIELD_ASSIGNEE,
|
2013-10-04 02:53:12 +02:00
|
|
|
self::FIELD_CC,
|
|
|
|
self::FIELD_CONTENT_SOURCE,
|
2013-11-11 23:19:12 +01:00
|
|
|
self::FIELD_PROJECTS,
|
2013-10-04 02:53:12 +02:00
|
|
|
),
|
|
|
|
parent::getFields());
|
2013-09-25 20:50:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getActions($rule_type) {
|
|
|
|
switch ($rule_type) {
|
|
|
|
case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL:
|
|
|
|
return array(
|
|
|
|
self::ACTION_ADD_CC,
|
2013-09-27 00:04:55 +02:00
|
|
|
self::ACTION_ASSIGN_TASK,
|
|
|
|
self::ACTION_ADD_PROJECTS,
|
2013-09-25 20:50:15 +02:00
|
|
|
self::ACTION_NOTHING,
|
|
|
|
);
|
|
|
|
case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL:
|
|
|
|
return array(
|
|
|
|
self::ACTION_ADD_CC,
|
|
|
|
self::ACTION_FLAG,
|
2013-09-27 00:04:55 +02:00
|
|
|
self::ACTION_ASSIGN_TASK,
|
2013-09-25 20:50:15 +02:00
|
|
|
self::ACTION_NOTHING,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPHID() {
|
|
|
|
return $this->getTask()->getPHID();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getHeraldName() {
|
|
|
|
return 'T'.$this->getTask()->getID();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getHeraldField($field) {
|
|
|
|
switch ($field) {
|
|
|
|
case self::FIELD_TITLE:
|
|
|
|
return $this->getTask()->getTitle();
|
|
|
|
case self::FIELD_BODY:
|
|
|
|
return $this->getTask()->getDescription();
|
|
|
|
case self::FIELD_AUTHOR:
|
|
|
|
return $this->getTask()->getAuthorPHID();
|
2013-12-22 17:47:31 +01:00
|
|
|
case self::FIELD_ASSIGNEE:
|
|
|
|
return $this->getTask()->getOwnerPHID();
|
2013-09-25 20:50:15 +02:00
|
|
|
case self::FIELD_CC:
|
|
|
|
return $this->getTask()->getCCPHIDs();
|
2013-11-11 23:19:12 +01:00
|
|
|
case self::FIELD_PROJECTS:
|
|
|
|
return $this->getTask()->getProjectPHIDs();
|
2013-09-25 20:50:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return parent::getHeraldField($field);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function applyHeraldEffects(array $effects) {
|
|
|
|
assert_instances_of($effects, 'HeraldEffect');
|
|
|
|
|
|
|
|
$result = array();
|
|
|
|
foreach ($effects as $effect) {
|
|
|
|
$action = $effect->getAction();
|
|
|
|
switch ($action) {
|
|
|
|
case self::ACTION_NOTHING:
|
|
|
|
$result[] = new HeraldApplyTranscript(
|
|
|
|
$effect,
|
|
|
|
true,
|
|
|
|
pht('Great success at doing nothing.'));
|
|
|
|
break;
|
|
|
|
case self::ACTION_ADD_CC:
|
|
|
|
foreach ($effect->getTarget() as $phid) {
|
2013-10-05 21:55:34 +02:00
|
|
|
$this->ccPHIDs[] = $phid;
|
2013-09-25 20:50:15 +02:00
|
|
|
}
|
|
|
|
$result[] = new HeraldApplyTranscript(
|
|
|
|
$effect,
|
|
|
|
true,
|
|
|
|
pht('Added address to cc list.'));
|
|
|
|
break;
|
|
|
|
case self::ACTION_FLAG:
|
|
|
|
$result[] = parent::applyFlagEffect(
|
|
|
|
$effect,
|
|
|
|
$this->getTask()->getPHID());
|
|
|
|
break;
|
2013-09-27 00:04:55 +02:00
|
|
|
case self::ACTION_ASSIGN_TASK:
|
|
|
|
$target_array = $effect->getTarget();
|
|
|
|
$assign_phid = reset($target_array);
|
|
|
|
$this->setAssignPHID($assign_phid);
|
|
|
|
$result[] = new HeraldApplyTranscript(
|
|
|
|
$effect,
|
|
|
|
true,
|
|
|
|
pht('Assigned task.'));
|
|
|
|
break;
|
|
|
|
case self::ACTION_ADD_PROJECTS:
|
|
|
|
foreach ($effect->getTarget() as $phid) {
|
2013-10-05 21:55:34 +02:00
|
|
|
$this->projectPHIDs[] = $phid;
|
2013-09-27 00:04:55 +02:00
|
|
|
}
|
|
|
|
$result[] = new HeraldApplyTranscript(
|
|
|
|
$effect,
|
|
|
|
true,
|
|
|
|
pht('Added projects.'));
|
|
|
|
break;
|
2013-09-25 20:50:15 +02:00
|
|
|
default:
|
|
|
|
throw new Exception("No rules to handle action '{$action}'.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
}
|