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

Add herald support for Maniphest

Summary:
standing on the shoulders of the badass work to move Maniphest to ApplicationTransactions, this diff implements a few methods and adds an adapter class.

For now, we can add cc and flag tasks. I figure see what people ask for? Ref T1368.

Test Plan: created herald rules for title and description text hits. made tasks and verified CC and flags worked.

Reviewers: epriestley

Reviewed By: epriestley

CC: Korvin, aran

Maniphest Tasks: T1368, T1638

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

+142
+2
src/__phutil_library_map__.php
··· 629 629 'HeraldInvalidActionException' => 'applications/herald/engine/exception/HeraldInvalidActionException.php', 630 630 'HeraldInvalidConditionException' => 'applications/herald/engine/exception/HeraldInvalidConditionException.php', 631 631 'HeraldInvalidFieldException' => 'applications/herald/engine/exception/HeraldInvalidFieldException.php', 632 + 'HeraldManiphestTaskAdapter' => 'applications/herald/adapter/HeraldManiphestTaskAdapter.php', 632 633 'HeraldNewController' => 'applications/herald/controller/HeraldNewController.php', 633 634 'HeraldObjectTranscript' => 'applications/herald/storage/transcript/HeraldObjectTranscript.php', 634 635 'HeraldPHIDTypeRule' => 'applications/herald/phid/HeraldPHIDTypeRule.php', ··· 2692 2693 'HeraldInvalidActionException' => 'Exception', 2693 2694 'HeraldInvalidConditionException' => 'Exception', 2694 2695 'HeraldInvalidFieldException' => 'Exception', 2696 + 'HeraldManiphestTaskAdapter' => 'HeraldAdapter', 2695 2697 'HeraldNewController' => 'HeraldController', 2696 2698 'HeraldPHIDTypeRule' => 'PhabricatorPHIDType', 2697 2699 'HeraldPholioMockAdapter' => 'HeraldAdapter',
+114
src/applications/herald/adapter/HeraldManiphestTaskAdapter.php
··· 1 + <?php 2 + 3 + /** 4 + * @group herald 5 + */ 6 + final class HeraldManiphestTaskAdapter extends HeraldAdapter { 7 + 8 + private $task; 9 + private $ccPHIDs = array(); 10 + 11 + public function setTask(ManiphestTask $task) { 12 + $this->task = $task; 13 + return $this; 14 + } 15 + public function getTask() { 16 + return $this->task; 17 + } 18 + 19 + private function setCcPHIDs(array $cc_phids) { 20 + $this->ccPHIDs = $cc_phids; 21 + return $this; 22 + } 23 + public function getCcPHIDs() { 24 + return $this->ccPHIDs; 25 + } 26 + 27 + public function getAdapterContentName() { 28 + return pht('Maniphest Tasks'); 29 + } 30 + 31 + public function getFields() { 32 + return array( 33 + self::FIELD_TITLE, 34 + self::FIELD_BODY, 35 + self::FIELD_AUTHOR, 36 + self::FIELD_CC, 37 + ); 38 + } 39 + 40 + public function getActions($rule_type) { 41 + switch ($rule_type) { 42 + case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL: 43 + return array( 44 + self::ACTION_ADD_CC, 45 + self::ACTION_NOTHING, 46 + ); 47 + case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL: 48 + return array( 49 + self::ACTION_ADD_CC, 50 + self::ACTION_FLAG, 51 + self::ACTION_NOTHING, 52 + ); 53 + } 54 + } 55 + 56 + public function getPHID() { 57 + return $this->getTask()->getPHID(); 58 + } 59 + 60 + public function getHeraldName() { 61 + return 'T'.$this->getTask()->getID(); 62 + } 63 + 64 + public function getHeraldField($field) { 65 + switch ($field) { 66 + case self::FIELD_TITLE: 67 + return $this->getTask()->getTitle(); 68 + case self::FIELD_BODY: 69 + return $this->getTask()->getDescription(); 70 + case self::FIELD_AUTHOR: 71 + return $this->getTask()->getAuthorPHID(); 72 + case self::FIELD_CC: 73 + return $this->getTask()->getCCPHIDs(); 74 + } 75 + 76 + return parent::getHeraldField($field); 77 + } 78 + 79 + public function applyHeraldEffects(array $effects) { 80 + assert_instances_of($effects, 'HeraldEffect'); 81 + 82 + $result = array(); 83 + foreach ($effects as $effect) { 84 + $action = $effect->getAction(); 85 + switch ($action) { 86 + case self::ACTION_NOTHING: 87 + $result[] = new HeraldApplyTranscript( 88 + $effect, 89 + true, 90 + pht('Great success at doing nothing.')); 91 + break; 92 + case self::ACTION_ADD_CC: 93 + $add_cc = array(); 94 + foreach ($effect->getTarget() as $phid) { 95 + $add_cc[$phid] = true; 96 + } 97 + $this->setCcPHIDs(array_keys($add_cc)); 98 + $result[] = new HeraldApplyTranscript( 99 + $effect, 100 + true, 101 + pht('Added address to cc list.')); 102 + break; 103 + case self::ACTION_FLAG: 104 + $result[] = parent::applyFlagEffect( 105 + $effect, 106 + $this->getTask()->getPHID()); 107 + break; 108 + default: 109 + throw new Exception("No rules to handle action '{$action}'."); 110 + } 111 + } 112 + return $result; 113 + } 114 + }
+26
src/applications/maniphest/editor/ManiphestTransactionEditorPro.php
··· 189 189 return true; 190 190 } 191 191 192 + protected function supportsHerald() { 193 + return true; 194 + } 195 + 196 + protected function buildHeraldAdapter( 197 + PhabricatorLiskDAO $object, 198 + array $xactions) { 199 + 200 + return id(new HeraldManiphestTaskAdapter()) 201 + ->setTask($object); 202 + } 203 + 204 + protected function didApplyHeraldRules( 205 + PhabricatorLiskDAO $object, 206 + HeraldAdapter $adapter, 207 + HeraldTranscript $transcript) { 208 + 209 + $cc_phids = $adapter->getCcPHIDs(); 210 + if ($cc_phids) { 211 + $existing_cc = $object->getCCPHIDs(); 212 + $new_cc = array_unique(array_merge($cc_phids, $existing_cc)); 213 + $object->setCCPHIDs($new_cc); 214 + $object->save(); 215 + } 216 + } 217 + 192 218 }