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

Extend TransactionCommentQuery for Differential

Summary: Ref T2009. Ref T1460. Replace hard-coded garbage with a real Query-layer query.

Test Plan: Submitted inline comments in Differential.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T2009, T1460

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

+121 -33
+4
src/__phutil_library_map__.php
··· 339 339 'DifferentialDiff' => 'applications/differential/storage/DifferentialDiff.php', 340 340 'DifferentialDiffCreateController' => 'applications/differential/controller/DifferentialDiffCreateController.php', 341 341 'DifferentialDiffEditor' => 'applications/differential/editor/DifferentialDiffEditor.php', 342 + 'DifferentialDiffInlineCommentQuery' => 'applications/differential/query/DifferentialDiffInlineCommentQuery.php', 342 343 'DifferentialDiffPHIDType' => 'applications/differential/phid/DifferentialDiffPHIDType.php', 343 344 'DifferentialDiffProperty' => 'applications/differential/storage/DifferentialDiffProperty.php', 344 345 'DifferentialDiffQuery' => 'applications/differential/query/DifferentialDiffQuery.php', ··· 1692 1693 'PhabricatorDestructionEngine' => 'applications/system/engine/PhabricatorDestructionEngine.php', 1693 1694 'PhabricatorDeveloperConfigOptions' => 'applications/config/option/PhabricatorDeveloperConfigOptions.php', 1694 1695 'PhabricatorDeveloperPreferencesSettingsPanel' => 'applications/settings/panel/PhabricatorDeveloperPreferencesSettingsPanel.php', 1696 + 'PhabricatorDiffInlineCommentQuery' => 'infrastructure/diff/query/PhabricatorDiffInlineCommentQuery.php', 1695 1697 'PhabricatorDiffPreferencesSettingsPanel' => 'applications/settings/panel/PhabricatorDiffPreferencesSettingsPanel.php', 1696 1698 'PhabricatorDifferenceEngine' => 'infrastructure/diff/PhabricatorDifferenceEngine.php', 1697 1699 'PhabricatorDifferentialApplication' => 'applications/differential/application/PhabricatorDifferentialApplication.php', ··· 3487 3489 ), 3488 3490 'DifferentialDiffCreateController' => 'DifferentialController', 3489 3491 'DifferentialDiffEditor' => 'PhabricatorApplicationTransactionEditor', 3492 + 'DifferentialDiffInlineCommentQuery' => 'PhabricatorDiffInlineCommentQuery', 3490 3493 'DifferentialDiffPHIDType' => 'PhabricatorPHIDType', 3491 3494 'DifferentialDiffProperty' => 'DifferentialDAO', 3492 3495 'DifferentialDiffQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', ··· 4974 4977 'PhabricatorDestructionEngine' => 'Phobject', 4975 4978 'PhabricatorDeveloperConfigOptions' => 'PhabricatorApplicationConfigOptions', 4976 4979 'PhabricatorDeveloperPreferencesSettingsPanel' => 'PhabricatorSettingsPanel', 4980 + 'PhabricatorDiffInlineCommentQuery' => 'PhabricatorApplicationTransactionCommentQuery', 4977 4981 'PhabricatorDiffPreferencesSettingsPanel' => 'PhabricatorSettingsPanel', 4978 4982 'PhabricatorDifferentialApplication' => 'PhabricatorApplication', 4979 4983 'PhabricatorDifferentialConfigOptions' => 'PhabricatorApplicationConfigOptions',
+31
src/applications/differential/query/DifferentialDiffInlineCommentQuery.php
··· 1 + <?php 2 + 3 + final class DifferentialDiffInlineCommentQuery 4 + extends PhabricatorDiffInlineCommentQuery { 5 + 6 + private $revisionPHIDs; 7 + 8 + public function withRevisionPHIDs(array $phids) { 9 + $this->revisionPHIDs = $phids; 10 + return $this; 11 + } 12 + 13 + protected function getTemplate() { 14 + return new DifferentialTransactionComment(); 15 + } 16 + 17 + protected function buildWhereClauseComponents( 18 + AphrontDatabaseConnection $conn_r) { 19 + $where = parent::buildWhereClauseComponents($conn_r); 20 + 21 + if ($this->revisionPHIDs !== null) { 22 + $where[] = qsprintf( 23 + $conn_r, 24 + 'revisionPHID IN (%Ls)', 25 + $this->revisionPHIDs); 26 + } 27 + 28 + return $where; 29 + } 30 + 31 + }
+6 -30
src/applications/differential/query/DifferentialTransactionQuery.php
··· 11 11 PhabricatorUser $viewer, 12 12 DifferentialRevision $revision) { 13 13 14 - // TODO: Subclass ApplicationTransactionCommentQuery to do this for real. 15 - 16 - $table = new DifferentialTransactionComment(); 17 - $conn_r = $table->establishConnection('r'); 18 - 19 - $phids = queryfx_all( 20 - $conn_r, 21 - 'SELECT phid FROM %T 22 - WHERE revisionPHID = %s 23 - AND authorPHID = %s 24 - AND transactionPHID IS NULL 25 - AND isDeleted = 0', 26 - $table->getTableName(), 27 - $revision->getPHID(), 28 - $viewer->getPHID()); 29 - 30 - $phids = ipull($phids, 'phid'); 31 - if (!$phids) { 32 - return array(); 33 - } 34 - 35 - $comments = id(new PhabricatorApplicationTransactionTemplatedCommentQuery()) 36 - ->setTemplate(new DifferentialTransactionComment()) 14 + return id(new DifferentialDiffInlineCommentQuery()) 37 15 ->setViewer($viewer) 38 - ->withPHIDs($phids) 16 + ->withRevisionPHIDs(array($revision->getPHID())) 17 + ->withAuthorPHIDs(array($viewer->getPHID())) 18 + ->withHasTransaction(false) 19 + ->withIsDeleted(false) 20 + ->needReplyToComments(true) 39 21 ->execute(); 40 - 41 - $comments = PhabricatorInlineCommentController::loadAndAttachReplies( 42 - $viewer, 43 - $comments); 44 - 45 - return $comments; 46 22 } 47 23 48 24 }
+27 -3
src/applications/transactions/query/PhabricatorApplicationTransactionCommentQuery.php
··· 8 8 private $phids; 9 9 private $transactionPHIDs; 10 10 private $isDeleted; 11 + private $hasTransaction; 11 12 12 13 abstract protected function getTemplate(); 13 14 ··· 31 32 return $this; 32 33 } 33 34 34 - public function withDeleted($deleted) { 35 + public function withIsDeleted($deleted) { 35 36 $this->isDeleted = $deleted; 37 + return $this; 38 + } 39 + 40 + public function withHasTransaction($has_transaction) { 41 + $this->hasTransaction = $has_transaction; 36 42 return $this; 37 43 } 38 44 ··· 51 57 return $table->loadAllFromArray($data); 52 58 } 53 59 54 - protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { 60 + private function buildWhereClause(AphrontDatabaseConnection $conn_r) { 61 + return $this->formatWhereClause($this->buildWhereClauseComponents($conn_r)); 62 + } 63 + 64 + protected function buildWhereClauseComponents( 65 + AphrontDatabaseConnection $conn_r) { 66 + 55 67 $where = array(); 56 68 57 69 if ($this->ids !== null) { ··· 89 101 (int)$this->isDeleted); 90 102 } 91 103 92 - return $this->formatWhereClause($where); 104 + if ($this->hasTransaction !== null) { 105 + if ($this->hasTransaction) { 106 + $where[] = qsprintf( 107 + $conn_r, 108 + 'xcomment.transactionPHID IS NOT NULL'); 109 + } else { 110 + $where[] = qsprintf( 111 + $conn_r, 112 + 'xcomment.transactionPHID IS NULL'); 113 + } 114 + } 115 + 116 + return $where; 93 117 } 94 118 95 119 public function getQueryApplicationClass() {
+53
src/infrastructure/diff/query/PhabricatorDiffInlineCommentQuery.php
··· 1 + <?php 2 + 3 + abstract class PhabricatorDiffInlineCommentQuery 4 + extends PhabricatorApplicationTransactionCommentQuery { 5 + 6 + private $needReplyToComments; 7 + 8 + public function needReplyToComments($need_reply_to) { 9 + $this->needReplyToComments = $need_reply_to; 10 + return $this; 11 + } 12 + 13 + protected function willFilterPage(array $comments) { 14 + if ($this->needReplyToComments) { 15 + $reply_phids = array(); 16 + foreach ($comments as $comment) { 17 + $reply_phid = $comment->getReplyToCommentPHID(); 18 + if ($reply_phid) { 19 + $reply_phids[] = $reply_phid; 20 + } 21 + } 22 + 23 + if ($reply_phids) { 24 + $reply_comments = newv(get_class($this), array()) 25 + ->setViewer($this->getViewer()) 26 + ->setParentQuery($this) 27 + ->withPHIDs($reply_phids) 28 + ->execute(); 29 + $reply_comments = mpull($reply_comments, null, 'getPHID'); 30 + } else { 31 + $reply_comments = array(); 32 + } 33 + 34 + foreach ($comments as $key => $comment) { 35 + $reply_phid = $comment->getReplyToCommentPHID(); 36 + if (!$reply_phid) { 37 + $comment->attachReplyToComment(null); 38 + continue; 39 + } 40 + $reply = idx($reply_comments, $reply_phid); 41 + if (!$reply) { 42 + $this->didRejectResult($comment); 43 + unset($comments[$key]); 44 + continue; 45 + } 46 + $comment->attachReplyToComment($reply); 47 + } 48 + } 49 + 50 + return $comments; 51 + } 52 + 53 + }