Skip to content

Commit 3092efd

Browse files
author
epriestley
committed
Reduce reliance on getRevisionID() on DifferentialComment
Summary: Ref T2222. A few rendering interfaces rely on fishing the revision ID out of a DifferentialComment, but it will only have the PHID soon. Pass in the revision and use it to determine the ID instead. Test Plan: Browsed, previewed, examined comments. Clicked anchors. Reviewers: btrahan, chad Reviewed By: btrahan CC: aran Maniphest Tasks: T2222 Differential Revision: https://secure.phabricator.com/D8209
1 parent 143b892 commit 3092efd

File tree

5 files changed

+37
-7
lines changed

5 files changed

+37
-7
lines changed

src/applications/differential/conduit/ConduitAPI_differential_getrevisioncomments_Method.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ protected function execute(ConduitAPIRequest $request) {
5353
}
5454

5555
foreach ($comments as $comment) {
56+
// TODO: Sort this out in the ID -> PHID change.
5657
$revision_id = $comment->getRevisionID();
5758
$result = array(
5859
'revisionID' => $revision_id,

src/applications/differential/controller/DifferentialCommentPreviewController.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,20 @@ public function willProcessRequest(array $data) {
1010
}
1111

1212
public function processRequest() {
13-
1413
$request = $this->getRequest();
14+
$viewer = $request->getUser();
15+
16+
$revision = id(new DifferentialRevisionQuery())
17+
->setViewer($viewer)
18+
->withIDs(array($this->id))
19+
->executeOne();
20+
if (!$revision) {
21+
return new Aphront404Response();
22+
}
1523

16-
$author_phid = $request->getUser()->getPHID();
17-
24+
$author_phid = $viewer->getPHID();
1825
$action = $request->getStr('action');
1926

20-
2127
$comment = new DifferentialComment();
2228
$comment->setContent($request->getStr('content'));
2329
$comment->setAction($action);
@@ -51,6 +57,7 @@ public function processRequest() {
5157
$view->setComment($comment);
5258
$view->setHandles($handles);
5359
$view->setMarkupEngine($engine);
60+
$view->setRevision($revision);
5461
$view->setPreview(true);
5562
$view->setTargetDiff(null);
5663

src/applications/differential/controller/DifferentialRevisionViewController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ public function processRequest() {
266266
$comment_view->setUser($user);
267267
$comment_view->setTargetDiff($target);
268268
$comment_view->setVersusDiffID($diff_vs);
269+
$comment_view->setRevision($revision);
269270

270271
if ($arc_project) {
271272
Javelin::initBehavior(

src/applications/differential/view/DifferentialRevisionCommentListView.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ final class DifferentialRevisionCommentListView extends AphrontView {
99
private $target;
1010
private $versusDiffID;
1111
private $id;
12+
private $revision;
13+
14+
public function setRevision(DifferentialRevision $revision) {
15+
$this->revision = $revision;
16+
return $this;
17+
}
18+
19+
public function getRevision() {
20+
return $this->revision;
21+
}
1222

1323
public function setComments(array $comments) {
1424
assert_instances_of($comments, 'DifferentialComment');
@@ -86,6 +96,7 @@ public function render() {
8696
$view->setInlineComments(idx($inlines, $comment->getID(), array()));
8797
$view->setChangesets($this->changesets);
8898
$view->setTargetDiff($this->target);
99+
$view->setRevision($this->getRevision());
89100
$view->setVersusDiffID($this->versusDiffID);
90101
if ($comment->getAction() == DifferentialAction::ACTION_SUMMARIZE) {
91102
$view->setAnchorName('summary');

src/applications/differential/view/DifferentialRevisionCommentView.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ final class DifferentialRevisionCommentView extends AphrontView {
1111
private $target;
1212
private $anchorName;
1313
private $versusDiffID;
14+
private $revision;
15+
16+
public function setRevision(DifferentialRevision $revision) {
17+
$this->revision = $revision;
18+
return $this;
19+
}
20+
21+
public function getRevision() {
22+
return $this->revision;
23+
}
1424

1525
public function setComment($comment) {
1626
$this->comment = $comment;
@@ -134,7 +144,7 @@ public function render() {
134144
$diff_link = phutil_tag(
135145
'a',
136146
array(
137-
'href' => '/D'.$comment->getRevisionID().'?id='.$diff_id,
147+
'href' => '/D'.$this->getRevision()->getID().'?id='.$diff_id,
138148
),
139149
'Diff #'.$diff_id);
140150
$actions[] = pht(
@@ -190,7 +200,7 @@ public function render() {
190200
$xaction_view->setEpoch($comment->getDateCreated());
191201
if ($this->anchorName) {
192202
$anchor_text =
193-
'D'.$comment->getRevisionID().
203+
'D'.$this->getRevision()->getID().
194204
'#'.preg_replace('/^comment-/', '', $this->anchorName);
195205

196206
$xaction_view->setAnchor($this->anchorName, $anchor_text);
@@ -279,7 +289,7 @@ private function renderInlineComments() {
279289
$diff_id = $changeset->getDiffID();
280290
$item['where'] = '(On Diff #'.$diff_id.')';
281291
$item['href'] =
282-
'D'.$this->comment->getRevisionID().
292+
'D'.$this->getRevision()->getID().
283293
'?id='.$diff_id.
284294
'#inline-'.$inline->getID();
285295
}

0 commit comments

Comments
 (0)