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
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
$drequest = $this->diffusionRequest;
|
|
|
|
$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();
|
|
|
|
}
|
|
|
|
|
|
|
|
$edit_uri = $this->getRepositoryControllerURI($repository, 'edit/');
|
|
|
|
|
|
|
|
$v_name = $repository->getName();
|
|
|
|
$v_desc = $repository->getDetail('description');
|
|
|
|
$e_name = true;
|
|
|
|
$errors = array();
|
|
|
|
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
$v_name = $request->getStr('name');
|
|
|
|
$v_desc = $request->getStr('description');
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
$xactions[] = id(clone $template)
|
|
|
|
->setTransactionType($type_name)
|
|
|
|
->setNewValue($v_name);
|
|
|
|
|
|
|
|
$xactions[] = id(clone $template)
|
|
|
|
->setTransactionType($type_desc)
|
|
|
|
->setNewValue($v_desc);
|
|
|
|
|
|
|
|
id(new PhabricatorRepositoryEditor())
|
|
|
|
->setContinueOnNoEffect(true)
|
|
|
|
->setContentSourceFromRequest($request)
|
|
|
|
->setActor($user)
|
|
|
|
->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());
|
|
|
|
|
2013-10-11 16:53:56 +02:00
|
|
|
$error_view = null;
|
2013-05-24 21:37:42 +02:00
|
|
|
if ($errors) {
|
2013-10-11 16:53:56 +02:00
|
|
|
$error_view = id(new AphrontErrorView())
|
2013-05-24 21:37:42 +02:00
|
|
|
->setTitle(pht('Form Errors'))
|
|
|
|
->setErrors($errors);
|
|
|
|
}
|
|
|
|
|
|
|
|
$form = id(new AphrontFormView())
|
|
|
|
->setUser($user)
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
->setName('name')
|
|
|
|
->setLabel(pht('Name'))
|
|
|
|
->setValue($v_name)
|
|
|
|
->setError($e_name))
|
|
|
|
->appendChild(
|
2013-05-24 21:38:44 +02:00
|
|
|
id(new PhabricatorRemarkupControl())
|
2013-05-24 21:37:42 +02:00
|
|
|
->setName('description')
|
|
|
|
->setLabel(pht('Description'))
|
|
|
|
->setValue($v_desc))
|
|
|
|
->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)
|
|
|
|
->setFormError($error_view);
|
2013-05-24 21:37:42 +02:00
|
|
|
|
|
|
|
return $this->buildApplicationPage(
|
2013-10-11 16:53:56 +02:00
|
|
|
array(
|
|
|
|
$crumbs,
|
|
|
|
$object_box),
|
2013-05-24 21:37:42 +02:00
|
|
|
array(
|
|
|
|
'title' => $title,
|
|
|
|
'device' => true,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2013-05-24 21:38:27 +02:00
|
|
|
private function getReadmeInstructions() {
|
|
|
|
return pht(<<<EOTEXT
|
|
|
|
You can also create a `README` file at the repository root (or in any
|
|
|
|
subdirectory) to provide information about the repository. These formats are
|
|
|
|
supported:
|
|
|
|
|
|
|
|
| File Name | Rendered As... |
|
|
|
|
|-----------------|----------------|
|
|
|
|
| `README` | Plain Text |
|
|
|
|
| `README.txt` | Plain Text |
|
|
|
|
| `README.remarkup` | Remarkup |
|
|
|
|
| `README.md` | Remarkup |
|
|
|
|
| `README.rainbow` | \xC2\xA1Fiesta! |
|
|
|
|
EOTEXT
|
|
|
|
);
|
|
|
|
}
|
2013-05-24 21:37:42 +02:00
|
|
|
|
|
|
|
}
|