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-14 22:16:58 +01:00
|
|
|
$type_comment = PhabricatorTransactions::TYPE_COMMENT;
|
|
|
|
$type_action = DifferentialTransaction::TYPE_ACTION;
|
|
|
|
$type_edge = PhabricatorTransactions::TYPE_EDGE;
|
|
|
|
$type_subscribers = PhabricatorTransactions::TYPE_SUBSCRIBERS;
|
|
|
|
|
|
|
|
$xactions = array();
|
2011-02-01 03:05:20 +01:00
|
|
|
|
2014-02-14 22:16:58 +01:00
|
|
|
$action = $request->getStr('action');
|
|
|
|
switch ($action) {
|
|
|
|
case DifferentialAction::ACTION_COMMENT:
|
|
|
|
case DifferentialAction::ACTION_ADDREVIEWERS:
|
|
|
|
case DifferentialAction::ACTION_ADDCCS:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$xactions[] = id(new DifferentialTransaction())
|
|
|
|
->setTransactionType($type_action)
|
|
|
|
->setNewValue($action);
|
|
|
|
break;
|
|
|
|
}
|
2011-02-01 03:05:20 +01:00
|
|
|
|
2014-02-14 22:16:58 +01:00
|
|
|
$edge_reviewer = PhabricatorEdgeConfig::TYPE_DREV_HAS_REVIEWER;
|
2011-12-23 02:59:00 +01:00
|
|
|
|
2012-09-20 23:11:11 +02:00
|
|
|
$reviewers = $request->getStrList('reviewers');
|
|
|
|
if (DifferentialAction::allowReviewers($action) && $reviewers) {
|
2014-02-14 22:16:58 +01:00
|
|
|
$faux_edges = array();
|
|
|
|
foreach ($reviewers as $phid) {
|
|
|
|
$faux_edges[$phid] = array(
|
|
|
|
'src' => $revision->getPHID(),
|
|
|
|
'type' => $edge_reviewer,
|
|
|
|
'dst' => $phid,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$xactions[] = id(new DifferentialTransaction())
|
|
|
|
->setTransactionType($type_edge)
|
|
|
|
->setMetadataValue('edge:type', $edge_reviewer)
|
|
|
|
->setOldValue(array())
|
|
|
|
->setNewValue($faux_edges);
|
2011-12-23 02:59:00 +01:00
|
|
|
}
|
|
|
|
|
2012-09-20 23:11:11 +02:00
|
|
|
$ccs = $request->getStrList('ccs');
|
2014-02-14 22:16:58 +01:00
|
|
|
if ($ccs) {
|
|
|
|
$xactions[] = id(new DifferentialTransaction())
|
|
|
|
->setTransactionType($type_subscribers)
|
|
|
|
->setOldValue(array())
|
|
|
|
->setNewValue(array_fuse($ccs));
|
2011-12-23 02:59:00 +01:00
|
|
|
}
|
|
|
|
|
2014-02-14 22:16:58 +01:00
|
|
|
// Add a comment transaction if there's nothing, so we'll generate a
|
|
|
|
// nonempty result.
|
|
|
|
if (strlen($request->getStr('content')) || !$xactions) {
|
|
|
|
$xactions[] = id(new DifferentialTransaction())
|
|
|
|
->setTransactionType($type_comment)
|
|
|
|
->attachComment(
|
|
|
|
id(new ManiphestTransactionComment())
|
|
|
|
->setContent($request->getStr('content')));
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($xactions as $xaction) {
|
|
|
|
$xaction->setAuthorPHID($viewer->getPHID());
|
|
|
|
}
|
2011-12-23 02:59:00 +01:00
|
|
|
|
2012-10-24 02:33:58 +02:00
|
|
|
$engine = new PhabricatorMarkupEngine();
|
|
|
|
$engine->setViewer($request->getUser());
|
2014-02-14 22:16:58 +01:00
|
|
|
foreach ($xactions as $xaction) {
|
|
|
|
if ($xaction->hasComment()) {
|
|
|
|
$engine->addObject(
|
|
|
|
$xaction->getComment(),
|
|
|
|
PhabricatorApplicationTransactionComment::MARKUP_FIELD_COMMENT);
|
|
|
|
}
|
|
|
|
}
|
2012-10-24 02:33:58 +02:00
|
|
|
$engine->process();
|
|
|
|
|
2014-02-14 22:16:58 +01:00
|
|
|
$phids = mpull($xactions, 'getRequiredHandlePHIDs');
|
|
|
|
$phids = array_mergev($phids);
|
|
|
|
|
|
|
|
$handles = id(new PhabricatorHandleQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withPHIDs($phids)
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
foreach ($xactions as $xaction) {
|
|
|
|
$xaction->setHandles($handles);
|
|
|
|
}
|
|
|
|
|
|
|
|
$view = id(new DifferentialTransactionView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setTransactions($xactions)
|
|
|
|
->setIsPreview(true);
|
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;
|
|
|
|
}
|
|
|
|
|
2014-02-19 01:25:16 +01:00
|
|
|
$draft_key = 'differential-comment-'.$this->id;
|
|
|
|
$draft = id(new PhabricatorDraft())
|
2014-02-14 22:16:58 +01:00
|
|
|
->setAuthorPHID($viewer->getPHID())
|
2014-02-19 01:25:16 +01:00
|
|
|
->setDraftKey($draft_key)
|
2014-02-14 22:16:58 +01:00
|
|
|
->setDraft($request->getStr('content'))
|
2012-10-02 00:50:47 +02:00
|
|
|
->setMetadata($metadata)
|
|
|
|
->replaceOrDelete();
|
2014-02-19 01:25:16 +01:00
|
|
|
if ($draft->isDeleted()) {
|
|
|
|
DifferentialDraft::deleteHasDraft(
|
|
|
|
$viewer->getPHID(),
|
|
|
|
$revision->getPHID(),
|
|
|
|
$draft_key);
|
|
|
|
} else {
|
|
|
|
DifferentialDraft::markHasDraft(
|
|
|
|
$viewer->getPHID(),
|
|
|
|
$revision->getPHID(),
|
|
|
|
$draft_key);
|
|
|
|
}
|
2011-02-06 01:57:21 +01:00
|
|
|
|
2011-02-01 03:05:20 +01:00
|
|
|
return id(new AphrontAjaxResponse())
|
2014-02-14 22:16:58 +01:00
|
|
|
->setContent((string)phutil_implode_html('', $view->buildEvents()));
|
2011-02-01 03:05:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|