mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-14 10:52:41 +01:00
3092efdc65
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
83 lines
2.3 KiB
PHP
83 lines
2.3 KiB
PHP
<?php
|
|
|
|
final class DifferentialCommentPreviewController
|
|
extends DifferentialController {
|
|
|
|
private $id;
|
|
|
|
public function willProcessRequest(array $data) {
|
|
$this->id = $data['id'];
|
|
}
|
|
|
|
public function processRequest() {
|
|
$request = $this->getRequest();
|
|
$viewer = $request->getUser();
|
|
|
|
$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);
|
|
$comment->setAuthorPHID($author_phid);
|
|
|
|
$handles = array($author_phid);
|
|
|
|
$reviewers = $request->getStrList('reviewers');
|
|
if (DifferentialAction::allowReviewers($action) && $reviewers) {
|
|
$comment->setMetadata(array(
|
|
DifferentialComment::METADATA_ADDED_REVIEWERS => $reviewers));
|
|
$handles = array_merge($handles, $reviewers);
|
|
}
|
|
|
|
$ccs = $request->getStrList('ccs');
|
|
if ($action == DifferentialAction::ACTION_ADDCCS && $ccs) {
|
|
$comment->setMetadata(array(
|
|
DifferentialComment::METADATA_ADDED_CCS => $ccs));
|
|
$handles = array_merge($handles, $ccs);
|
|
}
|
|
|
|
$handles = $this->loadViewerHandles($handles);
|
|
|
|
$engine = new PhabricatorMarkupEngine();
|
|
$engine->setViewer($request->getUser());
|
|
$engine->addObject($comment, DifferentialComment::MARKUP_FIELD_BODY);
|
|
$engine->process();
|
|
|
|
$view = new DifferentialRevisionCommentView();
|
|
$view->setUser($request->getUser());
|
|
$view->setComment($comment);
|
|
$view->setHandles($handles);
|
|
$view->setMarkupEngine($engine);
|
|
$view->setRevision($revision);
|
|
$view->setPreview(true);
|
|
$view->setTargetDiff(null);
|
|
|
|
$metadata = array(
|
|
'reviewers' => $reviewers,
|
|
'ccs' => $ccs,
|
|
);
|
|
if ($action != DifferentialAction::ACTION_COMMENT) {
|
|
$metadata['action'] = $action;
|
|
}
|
|
|
|
id(new PhabricatorDraft())
|
|
->setAuthorPHID($author_phid)
|
|
->setDraftKey('differential-comment-'.$this->id)
|
|
->setDraft($comment->getContent())
|
|
->setMetadata($metadata)
|
|
->replaceOrDelete();
|
|
|
|
return id(new AphrontAjaxResponse())
|
|
->setContent($view->render());
|
|
}
|
|
|
|
}
|