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

Prepare TransactionCommentQuery for extension

Summary:
Ref T2009. Ref T1460. The way Diffusion and Differential load inlines is horrible garbage right now:

- Differential does an ad-hoc query to get the PHIDs, then does a real load to policy check.
- Diffusion completely fakes things. In practice this is not a policy violation, but it's dangerous.

Make TransactionCommentQuery extensible so we can subclass it and get the query building correctly in the right Query layer.

Specifically, the Diffusion and Differential subclasses of this Query will add appropriate `withX()` methods to let us express the query in SQL.

Test Plan: Loaded, previewed, edited, and submitted inlines in Differential and Diffusion

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T2009, T1460

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

+81 -30
+2
src/__phutil_library_map__.php
··· 1298 1298 'PhabricatorApplicationTransactionResponse' => 'applications/transactions/response/PhabricatorApplicationTransactionResponse.php', 1299 1299 'PhabricatorApplicationTransactionShowOlderController' => 'applications/transactions/controller/PhabricatorApplicationTransactionShowOlderController.php', 1300 1300 'PhabricatorApplicationTransactionStructureException' => 'applications/transactions/exception/PhabricatorApplicationTransactionStructureException.php', 1301 + 'PhabricatorApplicationTransactionTemplatedCommentQuery' => 'applications/transactions/query/PhabricatorApplicationTransactionTemplatedCommentQuery.php', 1301 1302 'PhabricatorApplicationTransactionTextDiffDetailView' => 'applications/transactions/view/PhabricatorApplicationTransactionTextDiffDetailView.php', 1302 1303 'PhabricatorApplicationTransactionTransactionPHIDType' => 'applications/transactions/phid/PhabricatorApplicationTransactionTransactionPHIDType.php', 1303 1304 'PhabricatorApplicationTransactionValidationError' => 'applications/transactions/error/PhabricatorApplicationTransactionValidationError.php', ··· 4541 4542 'PhabricatorApplicationTransactionResponse' => 'AphrontProxyResponse', 4542 4543 'PhabricatorApplicationTransactionShowOlderController' => 'PhabricatorApplicationTransactionController', 4543 4544 'PhabricatorApplicationTransactionStructureException' => 'Exception', 4545 + 'PhabricatorApplicationTransactionTemplatedCommentQuery' => 'PhabricatorApplicationTransactionCommentQuery', 4544 4546 'PhabricatorApplicationTransactionTextDiffDetailView' => 'AphrontView', 4545 4547 'PhabricatorApplicationTransactionTransactionPHIDType' => 'PhabricatorPHIDType', 4546 4548 'PhabricatorApplicationTransactionValidationError' => 'Phobject',
+2 -6
src/applications/differential/query/DifferentialTransactionQuery.php
··· 11 11 PhabricatorUser $viewer, 12 12 DifferentialRevision $revision) { 13 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. 14 + // TODO: Subclass ApplicationTransactionCommentQuery to do this for real. 19 15 20 16 $table = new DifferentialTransactionComment(); 21 17 $conn_r = $table->establishConnection('r'); ··· 36 32 return array(); 37 33 } 38 34 39 - $comments = id(new PhabricatorApplicationTransactionCommentQuery()) 35 + $comments = id(new PhabricatorApplicationTransactionTemplatedCommentQuery()) 40 36 ->setTemplate(new DifferentialTransactionComment()) 41 37 ->setViewer($viewer) 42 38 ->withPHIDs($phids)
+1 -1
src/applications/transactions/controller/PhabricatorApplicationTransactionCommentHistoryController.php
··· 36 36 return new Aphront400Response(); 37 37 } 38 38 39 - $comments = id(new PhabricatorApplicationTransactionCommentQuery()) 39 + $comments = id(new PhabricatorApplicationTransactionTemplatedCommentQuery()) 40 40 ->setViewer($user) 41 41 ->setTemplate($xaction->getApplicationTransactionCommentObject()) 42 42 ->withTransactionPHIDs(array($xaction->getPHID()))
+46 -13
src/applications/transactions/query/PhabricatorApplicationTransactionCommentQuery.php
··· 1 1 <?php 2 2 3 - final class PhabricatorApplicationTransactionCommentQuery 3 + abstract class PhabricatorApplicationTransactionCommentQuery 4 4 extends PhabricatorCursorPagedPolicyAwareQuery { 5 5 6 - private $template; 7 - 6 + private $ids; 7 + private $authorPHIDs; 8 8 private $phids; 9 9 private $transactionPHIDs; 10 + private $isDeleted; 10 11 11 - public function setTemplate( 12 - PhabricatorApplicationTransactionComment $template) { 13 - $this->template = $template; 12 + abstract protected function getTemplate(); 13 + 14 + public function withIDs(array $ids) { 15 + $this->ids = $ids; 14 16 return $this; 15 17 } 16 18 ··· 24 26 return $this; 25 27 } 26 28 29 + public function withAuthorPHIDs(array $phids) { 30 + $this->authorPHIDs = $phids; 31 + return $this; 32 + } 33 + 34 + public function withDeleted($deleted) { 35 + $this->isDeleted = $deleted; 36 + return $this; 37 + } 38 + 27 39 protected function loadPage() { 28 - $table = $this->template; 40 + $table = $this->getTemplate(); 29 41 $conn_r = $table->establishConnection('r'); 30 42 31 43 $data = queryfx_all( 32 44 $conn_r, 33 - 'SELECT * FROM %T xc %Q %Q %Q', 45 + 'SELECT * FROM %T xcomment %Q %Q %Q', 34 46 $table->getTableName(), 35 47 $this->buildWhereClause($conn_r), 36 48 $this->buildOrderClause($conn_r), ··· 39 51 return $table->loadAllFromArray($data); 40 52 } 41 53 42 - private function buildWhereClause(AphrontDatabaseConnection $conn_r) { 54 + protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { 43 55 $where = array(); 44 56 45 - if ($this->phids) { 57 + if ($this->ids !== null) { 58 + $where[] = qsprintf( 59 + $conn_r, 60 + 'xcomment.id IN (%Ld)', 61 + $this->ids); 62 + } 63 + 64 + if ($this->phids !== null) { 46 65 $where[] = qsprintf( 47 66 $conn_r, 48 - 'phid IN (%Ls)', 67 + 'xcomment.phid IN (%Ls)', 49 68 $this->phids); 50 69 } 51 70 52 - if ($this->transactionPHIDs) { 71 + if ($this->authorPHIDs !== null) { 72 + $where[] = qsprintf( 73 + $conn_r, 74 + 'xcomment.authorPHID IN (%Ls)', 75 + $this->authorPHIDs); 76 + } 77 + 78 + if ($this->transactionPHIDs !== null) { 53 79 $where[] = qsprintf( 54 80 $conn_r, 55 - 'transactionPHID IN (%Ls)', 81 + 'xcomment.transactionPHID IN (%Ls)', 56 82 $this->transactionPHIDs); 83 + } 84 + 85 + if ($this->isDeleted !== null) { 86 + $where[] = qsprintf( 87 + $conn_r, 88 + 'xcomment.isDeleted = %d', 89 + (int)$this->isDeleted); 57 90 } 58 91 59 92 return $this->formatWhereClause($where);
+6 -5
src/applications/transactions/query/PhabricatorApplicationTransactionQuery.php
··· 80 80 81 81 $comments = array(); 82 82 if ($comment_phids) { 83 - $comments = id(new PhabricatorApplicationTransactionCommentQuery()) 84 - ->setTemplate($table->getApplicationTransactionCommentObject()) 85 - ->setViewer($this->getViewer()) 86 - ->withPHIDs($comment_phids) 87 - ->execute(); 83 + $comments = 84 + id(new PhabricatorApplicationTransactionTemplatedCommentQuery()) 85 + ->setTemplate($table->getApplicationTransactionCommentObject()) 86 + ->setViewer($this->getViewer()) 87 + ->withPHIDs($comment_phids) 88 + ->execute(); 88 89 $comments = mpull($comments, null, 'getPHID'); 89 90 } 90 91
+18
src/applications/transactions/query/PhabricatorApplicationTransactionTemplatedCommentQuery.php
··· 1 + <?php 2 + 3 + final class PhabricatorApplicationTransactionTemplatedCommentQuery 4 + extends PhabricatorApplicationTransactionCommentQuery { 5 + 6 + private $template; 7 + 8 + public function setTemplate( 9 + PhabricatorApplicationTransactionComment $template) { 10 + $this->template = $template; 11 + return $this; 12 + } 13 + 14 + protected function getTemplate() { 15 + return $this->template; 16 + } 17 + 18 + }
+6 -5
src/infrastructure/diff/PhabricatorInlineCommentController.php
··· 330 330 } 331 331 332 332 if ($reply_phids) { 333 - $reply_comments = id(new PhabricatorApplicationTransactionCommentQuery()) 334 - ->setTemplate($template) 335 - ->setViewer($viewer) 336 - ->withPHIDs($reply_phids) 337 - ->execute(); 333 + $reply_comments = 334 + id(new PhabricatorApplicationTransactionTemplatedCommentQuery()) 335 + ->setTemplate($template) 336 + ->setViewer($viewer) 337 + ->withPHIDs($reply_phids) 338 + ->execute(); 338 339 $reply_comments = mpull($reply_comments, null, 'getPHID'); 339 340 } else { 340 341 $reply_comments = array();