Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 7910757

Browse files
author
epriestley
committed
Remove "DifferentialInlineCommentQuery"
Summary: Ref T13513. Replaces "DifferentialInlineCommentQuery" with the similar but more modern "DifferentialDiffInlineCommentQuery". Test Plan: Viewed comments in timeline, changesets. Created, edited, and submitted comments. Hid and un-hid comments, reloading (saw state preserved). Maniphest Tasks: T13513 Differential Revision: https://secure.phabricator.com/D21233
1 parent 983d778 commit 7910757

8 files changed

+133
-175
lines changed

src/__phutil_library_map__.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,6 @@
561561
'DifferentialInlineComment' => 'applications/differential/storage/DifferentialInlineComment.php',
562562
'DifferentialInlineCommentEditController' => 'applications/differential/controller/DifferentialInlineCommentEditController.php',
563563
'DifferentialInlineCommentMailView' => 'applications/differential/mail/DifferentialInlineCommentMailView.php',
564-
'DifferentialInlineCommentQuery' => 'applications/differential/query/DifferentialInlineCommentQuery.php',
565564
'DifferentialJIRAIssuesCommitMessageField' => 'applications/differential/field/DifferentialJIRAIssuesCommitMessageField.php',
566565
'DifferentialJIRAIssuesField' => 'applications/differential/customfield/DifferentialJIRAIssuesField.php',
567566
'DifferentialLegacyQuery' => 'applications/differential/constants/DifferentialLegacyQuery.php',
@@ -3592,6 +3591,7 @@
35923591
'PhabricatorIndexableInterface' => 'applications/search/interface/PhabricatorIndexableInterface.php',
35933592
'PhabricatorInfrastructureTestCase' => '__tests__/PhabricatorInfrastructureTestCase.php',
35943593
'PhabricatorInlineComment' => 'infrastructure/diff/interface/PhabricatorInlineComment.php',
3594+
'PhabricatorInlineCommentAdjustmentEngine' => 'infrastructure/diff/engine/PhabricatorInlineCommentAdjustmentEngine.php',
35953595
'PhabricatorInlineCommentController' => 'infrastructure/diff/PhabricatorInlineCommentController.php',
35963596
'PhabricatorInlineCommentInterface' => 'applications/transactions/interface/PhabricatorInlineCommentInterface.php',
35973597
'PhabricatorInlineSummaryView' => 'infrastructure/diff/view/PhabricatorInlineSummaryView.php',
@@ -6626,7 +6626,6 @@
66266626
'DifferentialInlineComment' => 'PhabricatorInlineComment',
66276627
'DifferentialInlineCommentEditController' => 'PhabricatorInlineCommentController',
66286628
'DifferentialInlineCommentMailView' => 'DifferentialMailView',
6629-
'DifferentialInlineCommentQuery' => 'PhabricatorOffsetPagedQuery',
66306629
'DifferentialJIRAIssuesCommitMessageField' => 'DifferentialCommitMessageCustomField',
66316630
'DifferentialJIRAIssuesField' => 'DifferentialStoredCustomField',
66326631
'DifferentialLegacyQuery' => 'Phobject',
@@ -10118,6 +10117,7 @@
1011810117
'Phobject',
1011910118
'PhabricatorMarkupInterface',
1012010119
),
10120+
'PhabricatorInlineCommentAdjustmentEngine' => 'Phobject',
1012110121
'PhabricatorInlineCommentController' => 'PhabricatorController',
1012210122
'PhabricatorInlineSummaryView' => 'AphrontView',
1012310123
'PhabricatorInstructionsEditField' => 'PhabricatorEditField',

src/applications/differential/controller/DifferentialChangesetViewController.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,16 +194,23 @@ public function handleRequest(AphrontRequest $request) {
194194

195195
// Load both left-side and right-side inline comments.
196196
if ($revision) {
197-
$query = id(new DifferentialInlineCommentQuery())
197+
$inlines = id(new DifferentialDiffInlineCommentQuery())
198198
->setViewer($viewer)
199+
->withRevisionPHIDs(array($revision->getPHID()))
200+
->withPublishableComments(true)
201+
->withPublishedComments(true)
199202
->needHidden(true)
200-
->withRevisionPHIDs(array($revision->getPHID()));
201-
$inlines = $query->execute();
202-
$inlines = $query->adjustInlinesForChangesets(
203-
$inlines,
204-
$old,
205-
$new,
206-
$revision);
203+
->execute();
204+
205+
$inlines = mpull($inlines, 'newInlineCommentObject');
206+
207+
$inlines = id(new PhabricatorInlineCommentAdjustmentEngine())
208+
->setViewer($viewer)
209+
->setRevision($revision)
210+
->setOldChangesets($old)
211+
->setNewChangesets($new)
212+
->setInlines($inlines)
213+
->execute();
207214
} else {
208215
$inlines = array();
209216
}

src/applications/differential/controller/DifferentialRevisionViewController.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -227,16 +227,20 @@ public function handleRequest(AphrontRequest $request) {
227227
$old = array_select_keys($changesets, $old_ids);
228228
$new = array_select_keys($changesets, $new_ids);
229229

230-
$query = id(new DifferentialInlineCommentQuery())
230+
$inlines = id(new DifferentialDiffInlineCommentQuery())
231231
->setViewer($viewer)
232-
->needHidden(true)
233-
->withRevisionPHIDs(array($revision->getPHID()));
234-
$inlines = $query->execute();
235-
$inlines = $query->adjustInlinesForChangesets(
236-
$inlines,
237-
$old,
238-
$new,
239-
$revision);
232+
->withRevisionPHIDs(array($revision->getPHID()))
233+
->withPublishableComments(true)
234+
->withPublishedComments(true)
235+
->execute();
236+
237+
$inlines = id(new PhabricatorInlineCommentAdjustmentEngine())
238+
->setViewer($viewer)
239+
->setRevision($revision)
240+
->setOldChangesets($old)
241+
->setNewChangesets($new)
242+
->setInlines($inlines)
243+
->execute();
240244

241245
foreach ($inlines as $inline) {
242246
$changeset_id = $inline->getChangesetID();

src/applications/differential/engine/DifferentialRevisionTimelineEngine.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,22 @@ protected function newTimelineView() {
5050
}
5151

5252
foreach ($inlines as $key => $inline) {
53-
$inlines[$key] = DifferentialInlineComment::newFromModernComment(
54-
$inline);
53+
$inlines[$key] = $inline->newInlineCommentObject();
5554
}
5655

57-
$query = id(new DifferentialInlineCommentQuery())
58-
->needHidden(true)
59-
->setViewer($viewer);
60-
6156
// NOTE: This is a bit sketchy: this method adjusts the inlines as a
6257
// side effect, which means it will ultimately adjust the transaction
6358
// comments and affect timeline rendering.
64-
$query->adjustInlinesForChangesets(
65-
$inlines,
66-
array_select_keys($changesets, $old_ids),
67-
array_select_keys($changesets, $new_ids),
68-
$revision);
59+
60+
$old = array_select_keys($changesets, $old_ids);
61+
$new = array_select_keys($changesets, $new_ids);
62+
id(new PhabricatorInlineCommentAdjustmentEngine())
63+
->setViewer($viewer)
64+
->setRevision($revision)
65+
->setOldChangesets($old)
66+
->setNewChangesets($new)
67+
->setInlines($inlines)
68+
->execute();
6969

7070
return id(new DifferentialTransactionView())
7171
->setViewData($view_data)

src/applications/differential/query/DifferentialDiffInlineCommentQuery.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,26 @@ protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
4545
return $where;
4646
}
4747

48+
protected function loadHiddenCommentIDs(
49+
$viewer_phid,
50+
array $comments) {
51+
52+
$table = new DifferentialHiddenComment();
53+
$conn = $table->establishConnection('r');
54+
55+
$rows = queryfx_all(
56+
$conn,
57+
'SELECT commentID FROM %R
58+
WHERE userPHID = %s
59+
AND commentID IN (%Ld)',
60+
$table,
61+
$viewer_phid,
62+
mpull($comments, 'getID'));
63+
64+
$id_map = ipull($rows, 'commentID');
65+
$id_map = array_fuse($id_map);
66+
67+
return $id_map;
68+
}
69+
4870
}

src/applications/diffusion/query/DiffusionDiffInlineCommentQuery.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,10 @@ protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
6060
return $where;
6161
}
6262

63+
protected function loadHiddenCommentIDs(
64+
$viewer_phid,
65+
array $comments) {
66+
return array();
67+
}
68+
6369
}

src/applications/differential/query/DifferentialInlineCommentQuery.php renamed to src/infrastructure/diff/engine/PhabricatorInlineCommentAdjustmentEngine.php

Lines changed: 30 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
<?php
22

3-
/**
4-
* Temporary wrapper for transitioning Differential to ApplicationTransactions.
5-
*/
6-
final class DifferentialInlineCommentQuery
7-
extends PhabricatorOffsetPagedQuery {
3+
final class PhabricatorInlineCommentAdjustmentEngine
4+
extends Phobject {
85

9-
// TODO: Remove this when this query eventually moves to PolicyAware.
106
private $viewer;
11-
12-
private $ids;
13-
private $phids;
14-
private $drafts;
15-
private $authorPHIDs;
16-
private $revisionPHIDs;
17-
private $deletedDrafts;
18-
private $needHidden;
7+
private $inlines;
8+
private $revision;
9+
private $oldChangesets;
10+
private $newChangesets;
1911

2012
public function setViewer(PhabricatorUser $viewer) {
2113
$this->viewer = $viewer;
@@ -26,154 +18,51 @@ public function getViewer() {
2618
return $this->viewer;
2719
}
2820

29-
public function withIDs(array $ids) {
30-
$this->ids = $ids;
21+
public function setInlines(array $inlines) {
22+
assert_instances_of($inlines, 'DifferentialInlineComment');
23+
$this->inlines = $inlines;
3124
return $this;
3225
}
3326

34-
public function withPHIDs(array $phids) {
35-
$this->phids = $phids;
36-
return $this;
27+
public function getInlines() {
28+
return $this->inlines;
3729
}
3830

39-
public function withDrafts($drafts) {
40-
$this->drafts = $drafts;
31+
public function setOldChangesets(array $old_changesets) {
32+
assert_instances_of($old_changesets, 'DifferentialChangeset');
33+
$this->oldChangesets = $old_changesets;
4134
return $this;
4235
}
4336

44-
public function withAuthorPHIDs(array $author_phids) {
45-
$this->authorPHIDs = $author_phids;
46-
return $this;
37+
public function getOldChangesets() {
38+
return $this->oldChangesets;
4739
}
4840

49-
public function withRevisionPHIDs(array $revision_phids) {
50-
$this->revisionPHIDs = $revision_phids;
41+
public function setNewChangesets(array $new_changesets) {
42+
assert_instances_of($new_changesets, 'DifferentialChangeset');
43+
$this->newChangesets = $new_changesets;
5144
return $this;
5245
}
5346

54-
public function withDeletedDrafts($deleted_drafts) {
55-
$this->deletedDrafts = $deleted_drafts;
56-
return $this;
47+
public function getNewChangesets() {
48+
return $this->newChangesets;
5749
}
5850

59-
public function needHidden($need) {
60-
$this->needHidden = $need;
51+
public function setRevision(DifferentialRevision $revision) {
52+
$this->revision = $revision;
6153
return $this;
6254
}
6355

64-
public function execute() {
65-
$table = new DifferentialTransactionComment();
66-
$conn_r = $table->establishConnection('r');
67-
68-
$data = queryfx_all(
69-
$conn_r,
70-
'SELECT * FROM %T %Q %Q',
71-
$table->getTableName(),
72-
$this->buildWhereClause($conn_r),
73-
$this->buildLimitClause($conn_r));
74-
75-
$comments = $table->loadAllFromArray($data);
76-
77-
if ($this->needHidden) {
78-
$viewer_phid = $this->getViewer()->getPHID();
79-
if ($viewer_phid && $comments) {
80-
$hidden = queryfx_all(
81-
$conn_r,
82-
'SELECT commentID FROM %T WHERE userPHID = %s
83-
AND commentID IN (%Ls)',
84-
id(new DifferentialHiddenComment())->getTableName(),
85-
$viewer_phid,
86-
mpull($comments, 'getID'));
87-
$hidden = array_fuse(ipull($hidden, 'commentID'));
88-
} else {
89-
$hidden = array();
90-
}
91-
92-
foreach ($comments as $inline) {
93-
$inline->attachIsHidden(isset($hidden[$inline->getID()]));
94-
}
95-
}
96-
97-
foreach ($comments as $key => $value) {
98-
$comments[$key] = DifferentialInlineComment::newFromModernComment(
99-
$value);
100-
}
101-
102-
return $comments;
103-
}
104-
105-
public function executeOne() {
106-
// TODO: Remove when this query moves to PolicyAware.
107-
return head($this->execute());
56+
public function getRevision() {
57+
return $this->revision;
10858
}
10959

110-
protected function buildWhereClause(AphrontDatabaseConnection $conn) {
111-
$where = array();
112-
113-
// Only find inline comments.
114-
$where[] = qsprintf(
115-
$conn,
116-
'changesetID IS NOT NULL');
117-
118-
if ($this->ids !== null) {
119-
$where[] = qsprintf(
120-
$conn,
121-
'id IN (%Ld)',
122-
$this->ids);
123-
}
124-
125-
if ($this->phids !== null) {
126-
$where[] = qsprintf(
127-
$conn,
128-
'phid IN (%Ls)',
129-
$this->phids);
130-
}
131-
132-
if ($this->revisionPHIDs !== null) {
133-
$where[] = qsprintf(
134-
$conn,
135-
'revisionPHID IN (%Ls)',
136-
$this->revisionPHIDs);
137-
}
138-
139-
if ($this->drafts === null) {
140-
if ($this->deletedDrafts) {
141-
$where[] = qsprintf(
142-
$conn,
143-
'(authorPHID = %s) OR (transactionPHID IS NOT NULL)',
144-
$this->getViewer()->getPHID());
145-
} else {
146-
$where[] = qsprintf(
147-
$conn,
148-
'(authorPHID = %s AND isDeleted = 0)
149-
OR (transactionPHID IS NOT NULL)',
150-
$this->getViewer()->getPHID());
151-
}
152-
} else if ($this->drafts) {
153-
$where[] = qsprintf(
154-
$conn,
155-
'(authorPHID = %s AND isDeleted = 0) AND (transactionPHID IS NULL)',
156-
$this->getViewer()->getPHID());
157-
} else {
158-
$where[] = qsprintf(
159-
$conn,
160-
'transactionPHID IS NOT NULL');
161-
}
162-
163-
return $this->formatWhereClause($conn, $where);
164-
}
165-
166-
public function adjustInlinesForChangesets(
167-
array $inlines,
168-
array $old,
169-
array $new,
170-
DifferentialRevision $revision) {
171-
172-
assert_instances_of($inlines, 'DifferentialInlineComment');
173-
assert_instances_of($old, 'DifferentialChangeset');
174-
assert_instances_of($new, 'DifferentialChangeset');
175-
60+
public function execute() {
17661
$viewer = $this->getViewer();
62+
$inlines = $this->getInlines();
63+
$revision = $this->getRevision();
64+
$old = $this->getOldChangesets();
65+
$new = $this->getNewChangesets();
17766

17867
$no_ghosts = $viewer->compareUserSetting(
17968
PhabricatorOlderInlinesSetting::SETTINGKEY,

0 commit comments

Comments
 (0)