2013-05-24 21:37:42 +02:00
|
|
|
<?php
|
|
|
|
|
2013-10-26 00:58:58 +02:00
|
|
|
final class DiffusionRepositoryEditBasicController
|
|
|
|
extends DiffusionRepositoryEditController {
|
2013-05-24 21:37:42 +02:00
|
|
|
|
2016-01-05 17:49:10 +01:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$response = $this->loadDiffusionContextForEdit();
|
|
|
|
if ($response) {
|
|
|
|
return $response;
|
2013-05-24 21:37:42 +02:00
|
|
|
}
|
|
|
|
|
2016-01-05 17:49:10 +01:00
|
|
|
$viewer = $request->getUser();
|
|
|
|
$drequest = $this->getDiffusionRequest();
|
|
|
|
$repository = $drequest->getRepository();
|
|
|
|
|
2013-05-24 21:37:42 +02:00
|
|
|
$edit_uri = $this->getRepositoryControllerURI($repository, 'edit/');
|
|
|
|
|
|
|
|
$v_name = $repository->getName();
|
|
|
|
$v_desc = $repository->getDetail('description');
|
2014-01-30 20:42:10 +01:00
|
|
|
$v_clone_name = $repository->getDetail('clone-name');
|
2016-01-05 17:49:10 +01:00
|
|
|
$v_projects = PhabricatorEdgeQuery::loadDestinationPHIDs(
|
|
|
|
$repository->getPHID(),
|
|
|
|
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST);
|
2013-05-24 21:37:42 +02:00
|
|
|
$e_name = true;
|
|
|
|
$errors = array();
|
|
|
|
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
$v_name = $request->getStr('name');
|
|
|
|
$v_desc = $request->getStr('description');
|
2014-01-03 21:24:09 +01:00
|
|
|
$v_projects = $request->getArr('projectPHIDs');
|
2014-02-28 22:04:41 +01:00
|
|
|
|
|
|
|
if ($repository->isHosted()) {
|
|
|
|
$v_clone_name = $request->getStr('cloneName');
|
|
|
|
}
|
2013-05-24 21:37:42 +02:00
|
|
|
|
|
|
|
if (!strlen($v_name)) {
|
|
|
|
$e_name = pht('Required');
|
|
|
|
$errors[] = pht('Repository name is required.');
|
|
|
|
} else {
|
|
|
|
$e_name = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$errors) {
|
|
|
|
$xactions = array();
|
|
|
|
$template = id(new PhabricatorRepositoryTransaction());
|
|
|
|
|
|
|
|
$type_name = PhabricatorRepositoryTransaction::TYPE_NAME;
|
|
|
|
$type_desc = PhabricatorRepositoryTransaction::TYPE_DESCRIPTION;
|
2014-01-03 21:24:09 +01:00
|
|
|
$type_edge = PhabricatorTransactions::TYPE_EDGE;
|
2014-01-30 20:42:10 +01:00
|
|
|
$type_clone_name = PhabricatorRepositoryTransaction::TYPE_CLONE_NAME;
|
2013-05-24 21:37:42 +02:00
|
|
|
|
|
|
|
$xactions[] = id(clone $template)
|
|
|
|
->setTransactionType($type_name)
|
|
|
|
->setNewValue($v_name);
|
|
|
|
|
|
|
|
$xactions[] = id(clone $template)
|
|
|
|
->setTransactionType($type_desc)
|
|
|
|
->setNewValue($v_desc);
|
|
|
|
|
2014-01-30 20:42:10 +01:00
|
|
|
$xactions[] = id(clone $template)
|
|
|
|
->setTransactionType($type_clone_name)
|
|
|
|
->setNewValue($v_clone_name);
|
|
|
|
|
2014-01-03 21:24:09 +01:00
|
|
|
$xactions[] = id(clone $template)
|
|
|
|
->setTransactionType($type_edge)
|
|
|
|
->setMetadataValue(
|
|
|
|
'edge:type',
|
2014-07-18 00:42:19 +02:00
|
|
|
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST)
|
2014-01-03 21:24:09 +01:00
|
|
|
->setNewValue(
|
|
|
|
array(
|
|
|
|
'=' => array_fuse($v_projects),
|
|
|
|
));
|
|
|
|
|
2013-05-24 21:37:42 +02:00
|
|
|
id(new PhabricatorRepositoryEditor())
|
|
|
|
->setContinueOnNoEffect(true)
|
|
|
|
->setContentSourceFromRequest($request)
|
2016-01-05 17:49:10 +01:00
|
|
|
->setActor($viewer)
|
2013-05-24 21:37:42 +02:00
|
|
|
->applyTransactions($repository, $xactions);
|
|
|
|
|
|
|
|
return id(new AphrontRedirectResponse())->setURI($edit_uri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-26 00:58:58 +02:00
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
2013-12-19 02:47:34 +01:00
|
|
|
$crumbs->addTextCrumb(pht('Edit Basics'));
|
2013-05-24 21:37:42 +02:00
|
|
|
|
|
|
|
$title = pht('Edit %s', $repository->getName());
|
2014-01-03 21:24:09 +01:00
|
|
|
|
2013-05-24 21:37:42 +02:00
|
|
|
$form = id(new AphrontFormView())
|
2016-01-05 17:49:10 +01:00
|
|
|
->setUser($viewer)
|
2013-05-24 21:37:42 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
->setName('name')
|
|
|
|
->setLabel(pht('Name'))
|
|
|
|
->setValue($v_name)
|
2014-02-28 22:04:41 +01:00
|
|
|
->setError($e_name));
|
|
|
|
|
|
|
|
if ($repository->isHosted()) {
|
|
|
|
$form
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
->setName('cloneName')
|
|
|
|
->setLabel(pht('Clone/Checkout As'))
|
|
|
|
->setValue($v_clone_name)
|
|
|
|
->setCaption(
|
|
|
|
pht(
|
|
|
|
'Optional directory name to use when cloning or checking out '.
|
|
|
|
'this repository.')));
|
|
|
|
}
|
|
|
|
|
|
|
|
$form
|
2013-05-24 21:37:42 +02:00
|
|
|
->appendChild(
|
2013-05-24 21:38:44 +02:00
|
|
|
id(new PhabricatorRemarkupControl())
|
2016-01-05 17:49:10 +01:00
|
|
|
->setUser($viewer)
|
2013-05-24 21:37:42 +02:00
|
|
|
->setName('description')
|
|
|
|
->setLabel(pht('Description'))
|
|
|
|
->setValue($v_desc))
|
2015-03-31 23:10:55 +02:00
|
|
|
->appendControl(
|
2014-01-03 21:24:09 +01:00
|
|
|
id(new AphrontFormTokenizerControl())
|
2014-07-11 02:28:29 +02:00
|
|
|
->setDatasource(new PhabricatorProjectDatasource())
|
2014-01-03 21:24:09 +01:00
|
|
|
->setName('projectPHIDs')
|
|
|
|
->setLabel(pht('Projects'))
|
2016-01-05 17:49:10 +01:00
|
|
|
->setValue($v_projects))
|
2013-05-24 21:37:42 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSubmitControl())
|
|
|
|
->setValue(pht('Save'))
|
2013-05-24 21:38:27 +02:00
|
|
|
->addCancelButton($edit_uri))
|
|
|
|
->appendChild(id(new PHUIFormDividerControl()))
|
|
|
|
->appendRemarkupInstructions($this->getReadmeInstructions());
|
2013-05-24 21:37:42 +02:00
|
|
|
|
2013-10-11 16:53:56 +02:00
|
|
|
$object_box = id(new PHUIObjectBoxView())
|
|
|
|
->setHeaderText($title)
|
|
|
|
->setForm($form)
|
2014-01-10 18:17:37 +01:00
|
|
|
->setFormErrors($errors);
|
2013-05-24 21:37:42 +02:00
|
|
|
|
2016-01-05 17:49:10 +01:00
|
|
|
return $this->newPage()
|
|
|
|
->setTitle($title)
|
|
|
|
->setCrumbs($crumbs)
|
|
|
|
->appendChild($object_box);
|
2013-05-24 21:37:42 +02:00
|
|
|
}
|
|
|
|
|
2013-05-24 21:38:27 +02:00
|
|
|
private function getReadmeInstructions() {
|
|
|
|
return pht(<<<EOTEXT
|
2015-05-22 09:27:56 +02:00
|
|
|
You can also create a `%s` file at the repository root (or in any
|
2013-05-24 21:38:27 +02:00
|
|
|
subdirectory) to provide information about the repository. These formats are
|
|
|
|
supported:
|
|
|
|
|
2015-05-22 09:27:56 +02:00
|
|
|
| File Name | Rendered As... |
|
|
|
|
|-----------|-----------------|
|
|
|
|
| `%s` | Plain Text |
|
|
|
|
| `%s` | Plain Text |
|
|
|
|
| `%s` | Remarkup |
|
|
|
|
| `%s` | Remarkup |
|
|
|
|
| `%s` | \xC2\xA1Fiesta! |
|
2013-05-24 21:38:27 +02:00
|
|
|
EOTEXT
|
2015-05-22 09:27:56 +02:00
|
|
|
,
|
|
|
|
'README',
|
|
|
|
'README',
|
|
|
|
'README.txt',
|
|
|
|
'README.remarkup',
|
|
|
|
'README.md',
|
|
|
|
'README.rainbow');
|
2013-05-24 21:38:27 +02:00
|
|
|
}
|
2013-05-24 21:37:42 +02:00
|
|
|
|
|
|
|
}
|