Differential D13771 Diff 33264 src/applications/audit/controller/PhabricatorAuditPreviewController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/audit/controller/PhabricatorAuditPreviewController.php
<?php | <?php | ||||
final class PhabricatorAuditPreviewController | final class PhabricatorAuditPreviewController | ||||
extends PhabricatorAuditController { | extends PhabricatorAuditController { | ||||
private $id; | public function handleRequest(AphrontRequest $request) { | ||||
$viewer = $request->getViewer(); | |||||
$id = $request->getURIData('id'); | |||||
public function willProcessRequest(array $data) { | $commit = id(new PhabricatorRepositoryCommit())->load($id); | ||||
$this->id = $data['id']; | |||||
} | |||||
public function processRequest() { | |||||
$request = $this->getRequest(); | |||||
$user = $request->getUser(); | |||||
$commit = id(new PhabricatorRepositoryCommit())->load($this->id); | |||||
if (!$commit) { | if (!$commit) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
$xactions = array(); | $xactions = array(); | ||||
$action = $request->getStr('action'); | $action = $request->getStr('action'); | ||||
if ($action != PhabricatorAuditActionConstants::COMMENT) { | if ($action != PhabricatorAuditActionConstants::COMMENT) { | ||||
$action_xaction = id(new PhabricatorAuditTransaction()) | $action_xaction = id(new PhabricatorAuditTransaction()) | ||||
->setAuthorPHID($user->getPHID()) | ->setAuthorPHID($viewer->getPHID()) | ||||
->setObjectPHID($commit->getPHID()) | ->setObjectPHID($commit->getPHID()) | ||||
->setTransactionType(PhabricatorAuditActionConstants::ACTION) | ->setTransactionType(PhabricatorAuditActionConstants::ACTION) | ||||
->setNewValue($action); | ->setNewValue($action); | ||||
$auditors = $request->getStrList('auditors'); | $auditors = $request->getStrList('auditors'); | ||||
if ($action == PhabricatorAuditActionConstants::ADD_AUDITORS && | if ($action == PhabricatorAuditActionConstants::ADD_AUDITORS && | ||||
$auditors) { | $auditors) { | ||||
$action_xaction->setTransactionType($action); | $action_xaction->setTransactionType($action); | ||||
Show All 12 Lines | if ($action != PhabricatorAuditActionConstants::COMMENT) { | ||||
} | } | ||||
$xactions[] = $action_xaction; | $xactions[] = $action_xaction; | ||||
} | } | ||||
$content = $request->getStr('content'); | $content = $request->getStr('content'); | ||||
if (strlen($content)) { | if (strlen($content)) { | ||||
$xactions[] = id(new PhabricatorAuditTransaction()) | $xactions[] = id(new PhabricatorAuditTransaction()) | ||||
->setAuthorPHID($user->getPHID()) | ->setAuthorPHID($viewer->getPHID()) | ||||
->setObjectPHID($commit->getPHID()) | ->setObjectPHID($commit->getPHID()) | ||||
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT) | ->setTransactionType(PhabricatorTransactions::TYPE_COMMENT) | ||||
->attachComment( | ->attachComment( | ||||
id(new PhabricatorAuditTransactionComment()) | id(new PhabricatorAuditTransactionComment()) | ||||
->setContent($content)); | ->setContent($content)); | ||||
} | } | ||||
$phids = array(); | $phids = array(); | ||||
foreach ($xactions as $xaction) { | foreach ($xactions as $xaction) { | ||||
$phids[] = $xaction->getRequiredHandlePHIDs(); | $phids[] = $xaction->getRequiredHandlePHIDs(); | ||||
} | } | ||||
$phids = array_mergev($phids); | $phids = array_mergev($phids); | ||||
$handles = $this->loadViewerHandles($phids); | $handles = $this->loadViewerHandles($phids); | ||||
foreach ($xactions as $xaction) { | foreach ($xactions as $xaction) { | ||||
$xaction->setHandles($handles); | $xaction->setHandles($handles); | ||||
} | } | ||||
$view = id(new PhabricatorAuditTransactionView()) | $view = id(new PhabricatorAuditTransactionView()) | ||||
->setIsPreview(true) | ->setIsPreview(true) | ||||
->setUser($user) | ->setUser($viewer) | ||||
->setObjectPHID($commit->getPHID()) | ->setObjectPHID($commit->getPHID()) | ||||
->setTransactions($xactions); | ->setTransactions($xactions); | ||||
id(new PhabricatorDraft()) | id(new PhabricatorDraft()) | ||||
->setAuthorPHID($user->getPHID()) | ->setAuthorPHID($viewer->getPHID()) | ||||
->setDraftKey('diffusion-audit-'.$this->id) | ->setDraftKey('diffusion-audit-'.$id) | ||||
->setDraft($content) | ->setDraft($content) | ||||
->replaceOrDelete(); | ->replaceOrDelete(); | ||||
return id(new AphrontAjaxResponse())->setContent(hsprintf('%s', $view)); | return id(new AphrontAjaxResponse())->setContent(hsprintf('%s', $view)); | ||||
} | } | ||||
} | } |