2012-02-27 13:00:23 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorAuditPreviewController
|
|
|
|
extends PhabricatorAuditController {
|
|
|
|
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->id = $data['id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
|
|
|
$commit = id(new PhabricatorRepositoryCommit())->load($this->id);
|
|
|
|
if (!$commit) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2012-04-23 13:50:04 -07:00
|
|
|
$action = $request->getStr('action');
|
|
|
|
|
2012-02-27 13:00:23 -08:00
|
|
|
$comment = id(new PhabricatorAuditComment())
|
|
|
|
->setActorPHID($user->getPHID())
|
|
|
|
->setTargetPHID($commit->getPHID())
|
2012-04-23 13:50:04 -07:00
|
|
|
->setAction($action)
|
2012-02-27 13:00:23 -08:00
|
|
|
->setContent($request->getStr('content'));
|
|
|
|
|
2012-04-23 13:50:04 -07:00
|
|
|
$phids = array(
|
|
|
|
$user->getPHID(),
|
|
|
|
$commit->getPHID(),
|
|
|
|
);
|
|
|
|
|
|
|
|
$auditors = $request->getStrList('auditors');
|
|
|
|
if ($action == PhabricatorAuditActionConstants::ADD_AUDITORS && $auditors) {
|
|
|
|
$comment->setMetadata(array(
|
|
|
|
PhabricatorAuditComment::METADATA_ADDED_AUDITORS => $auditors));
|
|
|
|
$phids = array_merge($phids, $auditors);
|
|
|
|
}
|
|
|
|
|
|
|
|
$ccs = $request->getStrList('ccs');
|
|
|
|
if ($action == PhabricatorAuditActionConstants::ADD_CCS && $ccs) {
|
|
|
|
$comment->setMetadata(array(
|
|
|
|
PhabricatorAuditComment::METADATA_ADDED_CCS => $ccs));
|
|
|
|
$phids = array_merge($phids, $ccs);
|
|
|
|
}
|
|
|
|
|
2012-10-23 17:46:44 -07:00
|
|
|
$engine = new PhabricatorMarkupEngine();
|
|
|
|
$engine->setViewer($user);
|
|
|
|
$engine->addObject(
|
|
|
|
$comment,
|
|
|
|
PhabricatorAuditComment::MARKUP_FIELD_BODY);
|
|
|
|
$engine->process();
|
|
|
|
|
2012-02-27 13:00:23 -08:00
|
|
|
$view = id(new DiffusionCommentView())
|
2012-10-23 17:46:44 -07:00
|
|
|
->setMarkupEngine($engine)
|
2012-02-27 13:00:23 -08:00
|
|
|
->setUser($user)
|
|
|
|
->setComment($comment)
|
|
|
|
->setIsPreview(true);
|
|
|
|
|
2012-04-23 13:50:04 -07:00
|
|
|
$phids = array_merge($phids, $view->getRequiredHandlePHIDs());
|
|
|
|
|
2012-09-04 19:02:56 -07:00
|
|
|
$handles = $this->loadViewerHandles($phids);
|
2012-02-27 13:00:23 -08:00
|
|
|
$view->setHandles($handles);
|
|
|
|
|
|
|
|
id(new PhabricatorDraft())
|
|
|
|
->setAuthorPHID($comment->getActorPHID())
|
|
|
|
->setDraftKey('diffusion-audit-'.$this->id)
|
|
|
|
->setDraft($comment->getContent())
|
2012-10-01 15:50:47 -07:00
|
|
|
->replaceOrDelete();
|
2012-02-27 13:00:23 -08:00
|
|
|
|
|
|
|
return id(new AphrontAjaxResponse())
|
|
|
|
->setContent($view->render());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|