Differential D14945 Diff 36121 src/applications/diffusion/controller/DiffusionRepositoryEditStagingController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/controller/DiffusionRepositoryEditStagingController.php
<?php | <?php | ||||
final class DiffusionRepositoryEditStagingController | final class DiffusionRepositoryEditStagingController | ||||
extends DiffusionRepositoryEditController { | extends DiffusionRepositoryEditController { | ||||
protected function processDiffusionRequest(AphrontRequest $request) { | public function handleRequest(AphrontRequest $request) { | ||||
$user = $request->getUser(); | $response = $this->loadDiffusionContextForEdit(); | ||||
$drequest = $this->diffusionRequest; | if ($response) { | ||||
return $response; | |||||
} | |||||
$viewer = $this->getViewer(); | |||||
$drequest = $this->getDiffusionRequest(); | |||||
$repository = $drequest->getRepository(); | $repository = $drequest->getRepository(); | ||||
$repository = id(new PhabricatorRepositoryQuery()) | |||||
->setViewer($user) | |||||
->requireCapabilities( | |||||
array( | |||||
PhabricatorPolicyCapability::CAN_VIEW, | |||||
PhabricatorPolicyCapability::CAN_EDIT, | |||||
)) | |||||
->withIDs(array($repository->getID())) | |||||
->executeOne(); | |||||
if (!$repository) { | |||||
return new Aphront404Response(); | |||||
} | |||||
if (!$repository->supportsStaging()) { | if (!$repository->supportsStaging()) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
$edit_uri = $this->getRepositoryControllerURI($repository, 'edit/'); | $edit_uri = $this->getRepositoryControllerURI($repository, 'edit/'); | ||||
$v_area = $repository->getHumanReadableDetail('staging-uri'); | $v_area = $repository->getHumanReadableDetail('staging-uri'); | ||||
if ($request->isFormPost()) { | if ($request->isFormPost()) { | ||||
$v_area = $request->getStr('area'); | $v_area = $request->getStr('area'); | ||||
$xactions = array(); | $xactions = array(); | ||||
$template = id(new PhabricatorRepositoryTransaction()); | $template = id(new PhabricatorRepositoryTransaction()); | ||||
$type_encoding = PhabricatorRepositoryTransaction::TYPE_STAGING_URI; | $type_encoding = PhabricatorRepositoryTransaction::TYPE_STAGING_URI; | ||||
$xactions[] = id(clone $template) | $xactions[] = id(clone $template) | ||||
->setTransactionType($type_encoding) | ->setTransactionType($type_encoding) | ||||
->setNewValue($v_area); | ->setNewValue($v_area); | ||||
id(new PhabricatorRepositoryEditor()) | id(new PhabricatorRepositoryEditor()) | ||||
->setContinueOnNoEffect(true) | ->setContinueOnNoEffect(true) | ||||
->setContentSourceFromRequest($request) | ->setContentSourceFromRequest($request) | ||||
->setActor($user) | ->setActor($viewer) | ||||
->applyTransactions($repository, $xactions); | ->applyTransactions($repository, $xactions); | ||||
return id(new AphrontRedirectResponse())->setURI($edit_uri); | return id(new AphrontRedirectResponse())->setURI($edit_uri); | ||||
} | } | ||||
$crumbs = $this->buildApplicationCrumbs(); | $crumbs = $this->buildApplicationCrumbs(); | ||||
$crumbs->addTextCrumb(pht('Edit Staging')); | $crumbs->addTextCrumb(pht('Edit Staging')); | ||||
$title = pht('Edit %s', $repository->getName()); | $title = pht('Edit %s', $repository->getName()); | ||||
$form = id(new AphrontFormView()) | $form = id(new AphrontFormView()) | ||||
->setUser($user) | ->setUser($viewer) | ||||
->appendRemarkupInstructions( | ->appendRemarkupInstructions( | ||||
pht( | pht( | ||||
"To make it easier to run integration tests and builds on code ". | "To make it easier to run integration tests and builds on code ". | ||||
"under review, you can configure a **Staging Area**. When `arc` ". | "under review, you can configure a **Staging Area**. When `arc` ". | ||||
"creates a diff, it will push a copy of the changes to the ". | "creates a diff, it will push a copy of the changes to the ". | ||||
"configured staging area with a corresponding tag.". | "configured staging area with a corresponding tag.". | ||||
"\n\n". | "\n\n". | ||||
"IMPORTANT: This feature is new, experimental, and not supported. ". | "IMPORTANT: This feature is new, experimental, and not supported. ". | ||||
"Use it at your own risk.")) | "Use it at your own risk.")) | ||||
->appendChild( | ->appendChild( | ||||
id(new AphrontFormTextControl()) | id(new AphrontFormTextControl()) | ||||
->setLabel(pht('Staging Area URI')) | ->setLabel(pht('Staging Area URI')) | ||||
->setName('area') | ->setName('area') | ||||
->setValue($v_area)) | ->setValue($v_area)) | ||||
->appendChild( | ->appendChild( | ||||
id(new AphrontFormSubmitControl()) | id(new AphrontFormSubmitControl()) | ||||
->setValue(pht('Save')) | ->setValue(pht('Save')) | ||||
->addCancelButton($edit_uri)); | ->addCancelButton($edit_uri)); | ||||
$object_box = id(new PHUIObjectBoxView()) | $object_box = id(new PHUIObjectBoxView()) | ||||
->setHeaderText($title) | ->setHeaderText($title) | ||||
->setForm($form); | ->setForm($form); | ||||
return $this->buildApplicationPage( | return $this->newPage() | ||||
array( | ->setTitle($title) | ||||
$crumbs, | ->setCrumbs($crumbs) | ||||
$object_box, | ->appendChild($object_box); | ||||
), | |||||
array( | |||||
'title' => $title, | |||||
)); | |||||
} | } | ||||
} | } |