From 3092efdc65a47d8e3364da2db72137c626119d2c Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 12 Feb 2014 14:34:26 -0800 Subject: [PATCH] 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 --- ...I_differential_getrevisioncomments_Method.php | 1 + .../DifferentialCommentPreviewController.php | 13 ++++++++++--- .../DifferentialRevisionViewController.php | 1 + .../view/DifferentialRevisionCommentListView.php | 11 +++++++++++ .../view/DifferentialRevisionCommentView.php | 16 +++++++++++++--- 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/applications/differential/conduit/ConduitAPI_differential_getrevisioncomments_Method.php b/src/applications/differential/conduit/ConduitAPI_differential_getrevisioncomments_Method.php index d2aaf69e57..ee1531add0 100644 --- a/src/applications/differential/conduit/ConduitAPI_differential_getrevisioncomments_Method.php +++ b/src/applications/differential/conduit/ConduitAPI_differential_getrevisioncomments_Method.php @@ -53,6 +53,7 @@ final class ConduitAPI_differential_getrevisioncomments_Method } foreach ($comments as $comment) { + // TODO: Sort this out in the ID -> PHID change. $revision_id = $comment->getRevisionID(); $result = array( 'revisionID' => $revision_id, diff --git a/src/applications/differential/controller/DifferentialCommentPreviewController.php b/src/applications/differential/controller/DifferentialCommentPreviewController.php index cce6b36fcb..ce3fd356d0 100644 --- a/src/applications/differential/controller/DifferentialCommentPreviewController.php +++ b/src/applications/differential/controller/DifferentialCommentPreviewController.php @@ -10,14 +10,20 @@ final class DifferentialCommentPreviewController } public function processRequest() { - $request = $this->getRequest(); + $viewer = $request->getUser(); - $author_phid = $request->getUser()->getPHID(); + $revision = id(new DifferentialRevisionQuery()) + ->setViewer($viewer) + ->withIDs(array($this->id)) + ->executeOne(); + if (!$revision) { + return new Aphront404Response(); + } + $author_phid = $viewer->getPHID(); $action = $request->getStr('action'); - $comment = new DifferentialComment(); $comment->setContent($request->getStr('content')); $comment->setAction($action); @@ -51,6 +57,7 @@ final class DifferentialCommentPreviewController $view->setComment($comment); $view->setHandles($handles); $view->setMarkupEngine($engine); + $view->setRevision($revision); $view->setPreview(true); $view->setTargetDiff(null); diff --git a/src/applications/differential/controller/DifferentialRevisionViewController.php b/src/applications/differential/controller/DifferentialRevisionViewController.php index 8e15dd7de3..ef913b7863 100644 --- a/src/applications/differential/controller/DifferentialRevisionViewController.php +++ b/src/applications/differential/controller/DifferentialRevisionViewController.php @@ -266,6 +266,7 @@ final class DifferentialRevisionViewController extends DifferentialController { $comment_view->setUser($user); $comment_view->setTargetDiff($target); $comment_view->setVersusDiffID($diff_vs); + $comment_view->setRevision($revision); if ($arc_project) { Javelin::initBehavior( diff --git a/src/applications/differential/view/DifferentialRevisionCommentListView.php b/src/applications/differential/view/DifferentialRevisionCommentListView.php index b03cee03db..a6f72854ce 100644 --- a/src/applications/differential/view/DifferentialRevisionCommentListView.php +++ b/src/applications/differential/view/DifferentialRevisionCommentListView.php @@ -9,6 +9,16 @@ final class DifferentialRevisionCommentListView extends AphrontView { private $target; private $versusDiffID; private $id; + private $revision; + + public function setRevision(DifferentialRevision $revision) { + $this->revision = $revision; + return $this; + } + + public function getRevision() { + return $this->revision; + } public function setComments(array $comments) { assert_instances_of($comments, 'DifferentialComment'); @@ -86,6 +96,7 @@ final class DifferentialRevisionCommentListView extends AphrontView { $view->setInlineComments(idx($inlines, $comment->getID(), array())); $view->setChangesets($this->changesets); $view->setTargetDiff($this->target); + $view->setRevision($this->getRevision()); $view->setVersusDiffID($this->versusDiffID); if ($comment->getAction() == DifferentialAction::ACTION_SUMMARIZE) { $view->setAnchorName('summary'); diff --git a/src/applications/differential/view/DifferentialRevisionCommentView.php b/src/applications/differential/view/DifferentialRevisionCommentView.php index 9ec01df560..d661eb01d9 100644 --- a/src/applications/differential/view/DifferentialRevisionCommentView.php +++ b/src/applications/differential/view/DifferentialRevisionCommentView.php @@ -11,6 +11,16 @@ final class DifferentialRevisionCommentView extends AphrontView { private $target; private $anchorName; private $versusDiffID; + private $revision; + + public function setRevision(DifferentialRevision $revision) { + $this->revision = $revision; + return $this; + } + + public function getRevision() { + return $this->revision; + } public function setComment($comment) { $this->comment = $comment; @@ -134,7 +144,7 @@ final class DifferentialRevisionCommentView extends AphrontView { $diff_link = phutil_tag( 'a', array( - 'href' => '/D'.$comment->getRevisionID().'?id='.$diff_id, + 'href' => '/D'.$this->getRevision()->getID().'?id='.$diff_id, ), 'Diff #'.$diff_id); $actions[] = pht( @@ -190,7 +200,7 @@ final class DifferentialRevisionCommentView extends AphrontView { $xaction_view->setEpoch($comment->getDateCreated()); if ($this->anchorName) { $anchor_text = - 'D'.$comment->getRevisionID(). + 'D'.$this->getRevision()->getID(). '#'.preg_replace('/^comment-/', '', $this->anchorName); $xaction_view->setAnchor($this->anchorName, $anchor_text); @@ -279,7 +289,7 @@ final class DifferentialRevisionCommentView extends AphrontView { $diff_id = $changeset->getDiffID(); $item['where'] = '(On Diff #'.$diff_id.')'; $item['href'] = - 'D'.$this->comment->getRevisionID(). + 'D'.$this->getRevision()->getID(). '?id='.$diff_id. '#inline-'.$inline->getID(); }