Differential D13771 Diff 33264 src/applications/audit/controller/PhabricatorAuditAddCommentController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/audit/controller/PhabricatorAuditAddCommentController.php
<?php | <?php | ||||
final class PhabricatorAuditAddCommentController | final class PhabricatorAuditAddCommentController | ||||
extends PhabricatorAuditController { | extends PhabricatorAuditController { | ||||
public function processRequest() { | public function handleRequest(AphrontRequest $request) { | ||||
$request = $this->getRequest(); | $viewer = $request->getViewer(); | ||||
$user = $request->getUser(); | |||||
if (!$request->isFormPost()) { | if (!$request->isFormPost()) { | ||||
return new Aphront403Response(); | return new Aphront403Response(); | ||||
} | } | ||||
$commit_phid = $request->getStr('commit'); | $commit_phid = $request->getStr('commit'); | ||||
$commit = id(new DiffusionCommitQuery()) | $commit = id(new DiffusionCommitQuery()) | ||||
->setViewer($user) | ->setViewer($viewer) | ||||
->withPHIDs(array($commit_phid)) | ->withPHIDs(array($commit_phid)) | ||||
->needAuditRequests(true) | ->needAuditRequests(true) | ||||
->executeOne(); | ->executeOne(); | ||||
if (!$commit) { | if (!$commit) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
$xactions = array(); | $xactions = array(); | ||||
Show All 31 Lines | if (strlen($content)) { | ||||
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT) | ->setTransactionType(PhabricatorTransactions::TYPE_COMMENT) | ||||
->attachComment( | ->attachComment( | ||||
id(new PhabricatorAuditTransactionComment()) | id(new PhabricatorAuditTransactionComment()) | ||||
->setCommitPHID($commit->getPHID()) | ->setCommitPHID($commit->getPHID()) | ||||
->setContent($content)); | ->setContent($content)); | ||||
} | } | ||||
$inlines = PhabricatorAuditInlineComment::loadDraftComments( | $inlines = PhabricatorAuditInlineComment::loadDraftComments( | ||||
$user, | $viewer, | ||||
$commit->getPHID()); | $commit->getPHID()); | ||||
foreach ($inlines as $inline) { | foreach ($inlines as $inline) { | ||||
$xactions[] = id(new PhabricatorAuditTransaction()) | $xactions[] = id(new PhabricatorAuditTransaction()) | ||||
->setTransactionType(PhabricatorAuditActionConstants::INLINE) | ->setTransactionType(PhabricatorAuditActionConstants::INLINE) | ||||
->attachComment($inline->getTransactionComment()); | ->attachComment($inline->getTransactionComment()); | ||||
} | } | ||||
id(new PhabricatorAuditEditor()) | id(new PhabricatorAuditEditor()) | ||||
->setActor($user) | ->setActor($viewer) | ||||
->setContentSourceFromRequest($request) | ->setContentSourceFromRequest($request) | ||||
->setContinueOnMissingFields(true) | ->setContinueOnMissingFields(true) | ||||
->applyTransactions($commit, $xactions); | ->applyTransactions($commit, $xactions); | ||||
$draft = id(new PhabricatorDraft())->loadOneWhere( | $draft = id(new PhabricatorDraft())->loadOneWhere( | ||||
'authorPHID = %s AND draftKey = %s', | 'authorPHID = %s AND draftKey = %s', | ||||
$user->getPHID(), | $viewer->getPHID(), | ||||
'diffusion-audit-'.$commit->getID()); | 'diffusion-audit-'.$commit->getID()); | ||||
if ($draft) { | if ($draft) { | ||||
$draft->delete(); | $draft->delete(); | ||||
} | } | ||||
$monogram = $commit->getRepository()->getMonogram(); | $monogram = $commit->getRepository()->getMonogram(); | ||||
$identifier = $commit->getCommitIdentifier(); | $identifier = $commit->getCommitIdentifier(); | ||||
$uri = '/'.$monogram.$identifier; | $uri = '/'.$monogram.$identifier; | ||||
return id(new AphrontRedirectResponse())->setURI($uri); | return id(new AphrontRedirectResponse())->setURI($uri); | ||||
} | } | ||||
} | } |