2011-02-01 03:05:20 +01:00
|
|
|
<?php
|
|
|
|
|
2012-03-10 00:46:25 +01:00
|
|
|
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();
|
2014-02-12 23:34:26 +01:00
|
|
|
$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
|
|
|
|
2014-02-12 23:34:26 +01:00
|
|
|
$author_phid = $viewer->getPHID();
|
2011-12-23 02:59:00 +01:00
|
|
|
$action = $request->getStr('action');
|
2011-02-01 03:05:20 +01:00
|
|
|
|
|
|
|
$comment = new DifferentialComment();
|
|
|
|
$comment->setContent($request->getStr('content'));
|
2011-12-23 02:59:00 +01:00
|
|
|
$comment->setAction($action);
|
2011-02-01 03:05:20 +01:00
|
|
|
$comment->setAuthorPHID($author_phid);
|
|
|
|
|
2011-12-23 02:59:00 +01:00
|
|
|
$handles = array($author_phid);
|
|
|
|
|
2012-09-20 23:11:11 +02:00
|
|
|
$reviewers = $request->getStrList('reviewers');
|
|
|
|
if (DifferentialAction::allowReviewers($action) && $reviewers) {
|
2011-12-23 02:59:00 +01:00
|
|
|
$comment->setMetadata(array(
|
|
|
|
DifferentialComment::METADATA_ADDED_REVIEWERS => $reviewers));
|
|
|
|
$handles = array_merge($handles, $reviewers);
|
|
|
|
}
|
|
|
|
|
2012-09-20 23:11:11 +02:00
|
|
|
$ccs = $request->getStrList('ccs');
|
2011-12-23 02:59:00 +01:00
|
|
|
if ($action == DifferentialAction::ACTION_ADDCCS && $ccs) {
|
|
|
|
$comment->setMetadata(array(
|
|
|
|
DifferentialComment::METADATA_ADDED_CCS => $ccs));
|
|
|
|
$handles = array_merge($handles, $ccs);
|
|
|
|
}
|
|
|
|
|
2012-09-05 04:02:56 +02:00
|
|
|
$handles = $this->loadViewerHandles($handles);
|
2011-12-23 02:59:00 +01:00
|
|
|
|
2012-10-24 02:33:58 +02:00
|
|
|
$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();
|
Use phabricator_ time functions in more places
Summary:
Replace some more date() calls with locale-aware calls.
Also, at least on my system, the DateTimeZone / DateTime stuff didn't actually
work and always rendered in UTC. Fixed that.
Test Plan:
Viewed daemon console, differential revisions, files, and maniphest timestamps
in multiple timezones.
Reviewed By: toulouse
Reviewers: toulouse, fratrik, jungejason, aran, tuomaspelkonen
CC: aran, toulouse
Differential Revision: 530
2011-06-26 18:22:52 +02:00
|
|
|
$view->setUser($request->getUser());
|
2011-02-01 03:05:20 +01:00
|
|
|
$view->setComment($comment);
|
|
|
|
$view->setHandles($handles);
|
|
|
|
$view->setMarkupEngine($engine);
|
2014-02-12 23:34:26 +01:00
|
|
|
$view->setRevision($revision);
|
2011-02-01 03:05:20 +01:00
|
|
|
$view->setPreview(true);
|
2011-04-15 02:22:57 +02:00
|
|
|
$view->setTargetDiff(null);
|
2011-02-01 03:05:20 +01:00
|
|
|
|
2012-10-02 00:50:47 +02: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())
|
2012-10-02 00:50:47 +02:00
|
|
|
->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());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|