1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-14 19:02:41 +01:00
phorge-phorge/src/applications/differential/controller/DifferentialCommentPreviewController.php

84 lines
2.3 KiB
PHP
Raw Normal View History

2011-02-01 03:05:20 +01:00
<?php
final class DifferentialCommentPreviewController
extends DifferentialController {
2011-02-01 03:05:20 +01:00
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();
}
2011-02-01 03:05:20 +01:00
$author_phid = $viewer->getPHID();
$action = $request->getStr('action');
2011-02-01 03:05:20 +01:00
$comment = new DifferentialComment();
$comment->setContent($request->getStr('content'));
$comment->setAction($action);
2011-02-01 03:05:20 +01:00
$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();
2011-02-01 03:05:20 +01:00
$view = new DifferentialRevisionCommentView();
$view->setUser($request->getUser());
2011-02-01 03:05:20 +01:00
$view->setComment($comment);
$view->setHandles($handles);
$view->setMarkupEngine($engine);
$view->setRevision($revision);
2011-02-01 03:05:20 +01:00
$view->setPreview(true);
$view->setTargetDiff(null);
2011-02-01 03:05:20 +01:00
$metadata = array(
'reviewers' => $reviewers,
'ccs' => $ccs,
);
if ($action != DifferentialAction::ACTION_COMMENT) {
$metadata['action'] = $action;
}
id(new PhabricatorDraft())
2011-02-06 01:57:21 +01:00
->setAuthorPHID($author_phid)
->setDraftKey('differential-comment-'.$this->id)
->setDraft($comment->getContent())
->setMetadata($metadata)
->replaceOrDelete();
2011-02-06 01:57:21 +01:00
2011-02-01 03:05:20 +01:00
return id(new AphrontAjaxResponse())
->setContent($view->render());
}
}