Differential D14945 Diff 36121 src/applications/diffusion/controller/DiffusionRepositoryEditBasicController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/controller/DiffusionRepositoryEditBasicController.php
<?php | <?php | ||||
final class DiffusionRepositoryEditBasicController | final class DiffusionRepositoryEditBasicController | ||||
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) { | ||||
$repository = $drequest->getRepository(); | return $response; | ||||
$repository = id(new PhabricatorRepositoryQuery()) | |||||
->setViewer($user) | |||||
->requireCapabilities( | |||||
array( | |||||
PhabricatorPolicyCapability::CAN_VIEW, | |||||
PhabricatorPolicyCapability::CAN_EDIT, | |||||
)) | |||||
->needProjectPHIDs(true) | |||||
->withIDs(array($repository->getID())) | |||||
->executeOne(); | |||||
if (!$repository) { | |||||
return new Aphront404Response(); | |||||
} | } | ||||
$viewer = $request->getUser(); | |||||
$drequest = $this->getDiffusionRequest(); | |||||
$repository = $drequest->getRepository(); | |||||
$edit_uri = $this->getRepositoryControllerURI($repository, 'edit/'); | $edit_uri = $this->getRepositoryControllerURI($repository, 'edit/'); | ||||
$v_name = $repository->getName(); | $v_name = $repository->getName(); | ||||
$v_desc = $repository->getDetail('description'); | $v_desc = $repository->getDetail('description'); | ||||
$v_clone_name = $repository->getDetail('clone-name'); | $v_clone_name = $repository->getDetail('clone-name'); | ||||
$v_projects = PhabricatorEdgeQuery::loadDestinationPHIDs( | |||||
$repository->getPHID(), | |||||
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); | |||||
$e_name = true; | $e_name = true; | ||||
$errors = array(); | $errors = array(); | ||||
if ($request->isFormPost()) { | if ($request->isFormPost()) { | ||||
$v_name = $request->getStr('name'); | $v_name = $request->getStr('name'); | ||||
$v_desc = $request->getStr('description'); | $v_desc = $request->getStr('description'); | ||||
$v_projects = $request->getArr('projectPHIDs'); | $v_projects = $request->getArr('projectPHIDs'); | ||||
Show All 37 Lines | if ($request->isFormPost()) { | ||||
->setNewValue( | ->setNewValue( | ||||
array( | array( | ||||
'=' => array_fuse($v_projects), | '=' => array_fuse($v_projects), | ||||
)); | )); | ||||
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 Basics')); | $crumbs->addTextCrumb(pht('Edit Basics')); | ||||
$title = pht('Edit %s', $repository->getName()); | $title = pht('Edit %s', $repository->getName()); | ||||
$form = id(new AphrontFormView()) | $form = id(new AphrontFormView()) | ||||
->setUser($user) | ->setUser($viewer) | ||||
->appendChild( | ->appendChild( | ||||
id(new AphrontFormTextControl()) | id(new AphrontFormTextControl()) | ||||
->setName('name') | ->setName('name') | ||||
->setLabel(pht('Name')) | ->setLabel(pht('Name')) | ||||
->setValue($v_name) | ->setValue($v_name) | ||||
->setError($e_name)); | ->setError($e_name)); | ||||
if ($repository->isHosted()) { | if ($repository->isHosted()) { | ||||
$form | $form | ||||
->appendChild( | ->appendChild( | ||||
id(new AphrontFormTextControl()) | id(new AphrontFormTextControl()) | ||||
->setName('cloneName') | ->setName('cloneName') | ||||
->setLabel(pht('Clone/Checkout As')) | ->setLabel(pht('Clone/Checkout As')) | ||||
->setValue($v_clone_name) | ->setValue($v_clone_name) | ||||
->setCaption( | ->setCaption( | ||||
pht( | pht( | ||||
'Optional directory name to use when cloning or checking out '. | 'Optional directory name to use when cloning or checking out '. | ||||
'this repository.'))); | 'this repository.'))); | ||||
} | } | ||||
$form | $form | ||||
->appendChild( | ->appendChild( | ||||
id(new PhabricatorRemarkupControl()) | id(new PhabricatorRemarkupControl()) | ||||
->setUser($user) | ->setUser($viewer) | ||||
->setName('description') | ->setName('description') | ||||
->setLabel(pht('Description')) | ->setLabel(pht('Description')) | ||||
->setValue($v_desc)) | ->setValue($v_desc)) | ||||
->appendControl( | ->appendControl( | ||||
id(new AphrontFormTokenizerControl()) | id(new AphrontFormTokenizerControl()) | ||||
->setDatasource(new PhabricatorProjectDatasource()) | ->setDatasource(new PhabricatorProjectDatasource()) | ||||
->setName('projectPHIDs') | ->setName('projectPHIDs') | ||||
->setLabel(pht('Projects')) | ->setLabel(pht('Projects')) | ||||
->setValue($repository->getProjectPHIDs())) | ->setValue($v_projects)) | ||||
->appendChild( | ->appendChild( | ||||
id(new AphrontFormSubmitControl()) | id(new AphrontFormSubmitControl()) | ||||
->setValue(pht('Save')) | ->setValue(pht('Save')) | ||||
->addCancelButton($edit_uri)) | ->addCancelButton($edit_uri)) | ||||
->appendChild(id(new PHUIFormDividerControl())) | ->appendChild(id(new PHUIFormDividerControl())) | ||||
->appendRemarkupInstructions($this->getReadmeInstructions()); | ->appendRemarkupInstructions($this->getReadmeInstructions()); | ||||
$object_box = id(new PHUIObjectBoxView()) | $object_box = id(new PHUIObjectBoxView()) | ||||
->setHeaderText($title) | ->setHeaderText($title) | ||||
->setForm($form) | ->setForm($form) | ||||
->setFormErrors($errors); | ->setFormErrors($errors); | ||||
return $this->buildApplicationPage( | return $this->newPage() | ||||
array( | ->setTitle($title) | ||||
$crumbs, | ->setCrumbs($crumbs) | ||||
$object_box, | ->appendChild($object_box); | ||||
), | |||||
array( | |||||
'title' => $title, | |||||
)); | |||||
} | } | ||||
private function getReadmeInstructions() { | private function getReadmeInstructions() { | ||||
return pht(<<<EOTEXT | return pht(<<<EOTEXT | ||||
You can also create a `%s` file at the repository root (or in any | You can also create a `%s` file at the repository root (or in any | ||||
subdirectory) to provide information about the repository. These formats are | subdirectory) to provide information about the repository. These formats are | ||||
supported: | supported: | ||||
Show All 18 Lines |