Skip to content

Commit 7427a6e

Browse files
author
epriestley
committed
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
1 parent 4d86d51 commit 7427a6e

File tree

5 files changed

+121
-33
lines changed

5 files changed

+121
-33
lines changed

src/__phutil_library_map__.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@
339339
'DifferentialDiff' => 'applications/differential/storage/DifferentialDiff.php',
340340
'DifferentialDiffCreateController' => 'applications/differential/controller/DifferentialDiffCreateController.php',
341341
'DifferentialDiffEditor' => 'applications/differential/editor/DifferentialDiffEditor.php',
342+
'DifferentialDiffInlineCommentQuery' => 'applications/differential/query/DifferentialDiffInlineCommentQuery.php',
342343
'DifferentialDiffPHIDType' => 'applications/differential/phid/DifferentialDiffPHIDType.php',
343344
'DifferentialDiffProperty' => 'applications/differential/storage/DifferentialDiffProperty.php',
344345
'DifferentialDiffQuery' => 'applications/differential/query/DifferentialDiffQuery.php',
@@ -1692,6 +1693,7 @@
16921693
'PhabricatorDestructionEngine' => 'applications/system/engine/PhabricatorDestructionEngine.php',
16931694
'PhabricatorDeveloperConfigOptions' => 'applications/config/option/PhabricatorDeveloperConfigOptions.php',
16941695
'PhabricatorDeveloperPreferencesSettingsPanel' => 'applications/settings/panel/PhabricatorDeveloperPreferencesSettingsPanel.php',
1696+
'PhabricatorDiffInlineCommentQuery' => 'infrastructure/diff/query/PhabricatorDiffInlineCommentQuery.php',
16951697
'PhabricatorDiffPreferencesSettingsPanel' => 'applications/settings/panel/PhabricatorDiffPreferencesSettingsPanel.php',
16961698
'PhabricatorDifferenceEngine' => 'infrastructure/diff/PhabricatorDifferenceEngine.php',
16971699
'PhabricatorDifferentialApplication' => 'applications/differential/application/PhabricatorDifferentialApplication.php',
@@ -3487,6 +3489,7 @@
34873489
),
34883490
'DifferentialDiffCreateController' => 'DifferentialController',
34893491
'DifferentialDiffEditor' => 'PhabricatorApplicationTransactionEditor',
3492+
'DifferentialDiffInlineCommentQuery' => 'PhabricatorDiffInlineCommentQuery',
34903493
'DifferentialDiffPHIDType' => 'PhabricatorPHIDType',
34913494
'DifferentialDiffProperty' => 'DifferentialDAO',
34923495
'DifferentialDiffQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
@@ -4974,6 +4977,7 @@
49744977
'PhabricatorDestructionEngine' => 'Phobject',
49754978
'PhabricatorDeveloperConfigOptions' => 'PhabricatorApplicationConfigOptions',
49764979
'PhabricatorDeveloperPreferencesSettingsPanel' => 'PhabricatorSettingsPanel',
4980+
'PhabricatorDiffInlineCommentQuery' => 'PhabricatorApplicationTransactionCommentQuery',
49774981
'PhabricatorDiffPreferencesSettingsPanel' => 'PhabricatorSettingsPanel',
49784982
'PhabricatorDifferentialApplication' => 'PhabricatorApplication',
49794983
'PhabricatorDifferentialConfigOptions' => 'PhabricatorApplicationConfigOptions',
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
}

src/applications/differential/query/DifferentialTransactionQuery.php

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,14 @@ public static function loadUnsubmittedInlineComments(
1111
PhabricatorUser $viewer,
1212
DifferentialRevision $revision) {
1313

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())
3715
->setViewer($viewer)
38-
->withPHIDs($phids)
16+
->withRevisionPHIDs(array($revision->getPHID()))
17+
->withAuthorPHIDs(array($viewer->getPHID()))
18+
->withHasTransaction(false)
19+
->withIsDeleted(false)
20+
->needReplyToComments(true)
3921
->execute();
40-
41-
$comments = PhabricatorInlineCommentController::loadAndAttachReplies(
42-
$viewer,
43-
$comments);
44-
45-
return $comments;
4622
}
4723

4824
}

src/applications/transactions/query/PhabricatorApplicationTransactionCommentQuery.php

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ abstract class PhabricatorApplicationTransactionCommentQuery
88
private $phids;
99
private $transactionPHIDs;
1010
private $isDeleted;
11+
private $hasTransaction;
1112

1213
abstract protected function getTemplate();
1314

@@ -31,11 +32,16 @@ public function withAuthorPHIDs(array $phids) {
3132
return $this;
3233
}
3334

34-
public function withDeleted($deleted) {
35+
public function withIsDeleted($deleted) {
3536
$this->isDeleted = $deleted;
3637
return $this;
3738
}
3839

40+
public function withHasTransaction($has_transaction) {
41+
$this->hasTransaction = $has_transaction;
42+
return $this;
43+
}
44+
3945
protected function loadPage() {
4046
$table = $this->getTemplate();
4147
$conn_r = $table->establishConnection('r');
@@ -51,7 +57,13 @@ protected function loadPage() {
5157
return $table->loadAllFromArray($data);
5258
}
5359

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+
5567
$where = array();
5668

5769
if ($this->ids !== null) {
@@ -89,7 +101,19 @@ protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
89101
(int)$this->isDeleted);
90102
}
91103

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;
93117
}
94118

95119
public function getQueryApplicationClass() {
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
}

0 commit comments

Comments
 (0)