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

Use TransactionEditor in differential.createcomment

Summary: Ref T2222. Update this callsite; pretty straightforward.

Test Plan: Used Conduit to take actions and saw their effects in Differential.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2222

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

+97 -55
+39 -16
src/applications/differential/conduit/ConduitAPI_differential_createcomment_Method.php
··· 7 7 extends ConduitAPIMethod { 8 8 9 9 public function getMethodDescription() { 10 - return "Add a comment to a Differential revision."; 10 + return pht("Add a comment to a Differential revision."); 11 11 } 12 12 13 13 public function defineParamTypes() { ··· 31 31 } 32 32 33 33 protected function execute(ConduitAPIRequest $request) { 34 + $viewer = $request->getUser(); 35 + 34 36 $revision = id(new DifferentialRevisionQuery()) 35 - ->setViewer($request->getUser()) 37 + ->setViewer($viewer) 36 38 ->withIDs(array($request->getValue('revision_id'))) 39 + ->needReviewerStatus(true) 37 40 ->executeOne(); 38 41 if (!$revision) { 39 42 throw new ConduitException('ERR_BAD_REVISION'); 40 43 } 41 44 42 - $content_source = PhabricatorContentSource::newForSource( 43 - PhabricatorContentSource::SOURCE_CONDUIT, 44 - array()); 45 + $xactions = array(); 45 46 46 47 $action = $request->getValue('action'); 47 - if (!$action) { 48 - $action = 'none'; 48 + if ($action && ($action != 'comment')) { 49 + $xactions[] = id(new DifferentialTransaction()) 50 + ->setTransactionType(DifferentialTransaction::TYPE_ACTION) 51 + ->setNewValue($action); 52 + } 53 + 54 + $content = $request->getValue('message'); 55 + if (strlen($content)) { 56 + $xactions[] = id(new DifferentialTransaction()) 57 + ->setTransactionType(PhabricatorTransactions::TYPE_COMMENT) 58 + ->attachComment( 59 + id(new DifferentialTransactionComment()) 60 + ->setContent($content)); 61 + } 62 + 63 + if ($request->getValue('attach_inlines')) { 64 + $type_inline = DifferentialTransaction::TYPE_INLINE; 65 + $inlines = DifferentialTransactionQuery::loadUnsubmittedInlineComments( 66 + $viewer, 67 + $revision); 68 + foreach ($inlines as $inline) { 69 + $xactions[] = id(new DifferentialTransaction()) 70 + ->setTransactionType($type_inline) 71 + ->attachComment($inline); 72 + } 49 73 } 50 74 51 - $editor = new DifferentialCommentEditor( 52 - $revision, 53 - $action); 54 - $editor->setActor($request->getUser()); 55 - $editor->setContentSource($content_source); 56 - $editor->setMessage($request->getValue('message')); 57 - $editor->setNoEmail($request->getValue('silent')); 58 - $editor->setAttachInlineComments($request->getValue('attach_inlines')); 59 - $editor->save(); 75 + $editor = id(new DifferentialTransactionEditor()) 76 + ->setActor($viewer) 77 + ->setDisableEmail($request->getValue('silent')) 78 + ->setContentSourceFromConduitRequest($request) 79 + ->setContinueOnNoEffect(true) 80 + ->setContinueOnMissingFields(true); 81 + 82 + $editor->applyTransactions($revision, $xactions); 60 83 61 84 return array( 62 85 'revisionid' => $revision->getID(),
+3 -37
src/applications/differential/controller/DifferentialCommentSaveController.php
··· 87 87 ->setNewValue(array('+' => $reviewer_edges)); 88 88 } 89 89 90 - $inline_phids = $this->loadUnsubmittedInlinePHIDs($revision); 91 - if ($inline_phids) { 92 - $inlines = id(new PhabricatorApplicationTransactionCommentQuery()) 93 - ->setTemplate(new DifferentialTransactionComment()) 94 - ->setViewer($viewer) 95 - ->withPHIDs($inline_phids) 96 - ->execute(); 97 - } else { 98 - $inlines = array(); 99 - } 100 - 90 + $inlines = DifferentialTransactionQuery::loadUnsubmittedInlineComments( 91 + $viewer, 92 + $revision); 101 93 foreach ($inlines as $inline) { 102 94 $xactions[] = id(new DifferentialTransaction()) 103 95 ->setTransactionType($type_inline) ··· 151 143 152 144 return id(new AphrontRedirectResponse()) 153 145 ->setURI('/D'.$revision->getID()); 154 - } 155 - 156 - 157 - private function loadUnsubmittedInlinePHIDs(DifferentialRevision $revision) { 158 - $viewer = $this->getRequest()->getUser(); 159 - 160 - // TODO: This probably needs to move somewhere more central as we move 161 - // away from DifferentialInlineCommentQuery, but 162 - // PhabricatorApplicationTransactionCommentQuery is currently `final` and 163 - // I'm not yet decided on how to approach that. For now, just get the PHIDs 164 - // and then execute a PHID-based query through the standard stack. 165 - 166 - $table = new DifferentialTransactionComment(); 167 - $conn_r = $table->establishConnection('r'); 168 - 169 - $phids = queryfx_all( 170 - $conn_r, 171 - 'SELECT phid FROM %T 172 - WHERE revisionPHID = %s 173 - AND authorPHID = %s 174 - AND transactionPHID IS NULL', 175 - $table->getTableName(), 176 - $revision->getPHID(), 177 - $viewer->getPHID()); 178 - 179 - return ipull($phids, 'phid'); 180 146 } 181 147 182 148 }
+35
src/applications/differential/query/DifferentialTransactionQuery.php
··· 7 7 return new DifferentialTransaction(); 8 8 } 9 9 10 + public static function loadUnsubmittedInlineComments( 11 + PhabricatorUser $viewer, 12 + DifferentialRevision $revision) { 13 + 14 + // TODO: This probably needs to move somewhere more central as we move 15 + // away from DifferentialInlineCommentQuery, but 16 + // PhabricatorApplicationTransactionCommentQuery is currently `final` and 17 + // I'm not yet decided on how to approach that. For now, just get the PHIDs 18 + // and then execute a PHID-based query through the standard stack. 19 + 20 + $table = new DifferentialTransactionComment(); 21 + $conn_r = $table->establishConnection('r'); 22 + 23 + $phids = queryfx_all( 24 + $conn_r, 25 + 'SELECT phid FROM %T 26 + WHERE revisionPHID = %s 27 + AND authorPHID = %s 28 + AND transactionPHID IS NULL', 29 + $table->getTableName(), 30 + $revision->getPHID(), 31 + $viewer->getPHID()); 32 + 33 + $phids = ipull($phids, 'phid'); 34 + if (!$phids) { 35 + return array(); 36 + } 37 + 38 + return id(new PhabricatorApplicationTransactionCommentQuery()) 39 + ->setTemplate(new DifferentialTransactionComment()) 40 + ->setViewer($viewer) 41 + ->withPHIDs($phids) 42 + ->execute(); 43 + } 44 + 10 45 }
+20 -2
src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
··· 25 25 private $isPreview; 26 26 private $isHeraldEditor; 27 27 private $actingAsPHID; 28 + private $disableEmail; 28 29 29 30 public function setActingAsPHID($acting_as_phid) { 30 31 $this->actingAsPHID = $acting_as_phid; ··· 126 127 127 128 public function getIsHeraldEditor() { 128 129 return $this->isHeraldEditor; 130 + } 131 + 132 + /** 133 + * Prevent this editor from generating email when applying transactions. 134 + * 135 + * @param bool True to disable email. 136 + * @return this 137 + */ 138 + public function setDisableEmail($disable_email) { 139 + $this->disableEmail = $disable_email; 140 + return $this; 141 + } 142 + 143 + public function getDisableEmail() { 144 + return $this->disableEmail; 129 145 } 130 146 131 147 public function getTransactionTypes() { ··· 682 698 $this->loadHandles($xactions); 683 699 684 700 $mail = null; 685 - if ($this->shouldSendMail($object, $xactions)) { 686 - $mail = $this->sendMail($object, $xactions); 701 + if (!$this->getDisableEmail()) { 702 + if ($this->shouldSendMail($object, $xactions)) { 703 + $mail = $this->sendMail($object, $xactions); 704 + } 687 705 } 688 706 689 707 if ($this->supportsSearch()) {