1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-15 19:32:40 +01:00
phorge-phorge/src/applications/diffusion/controller/DiffusionRepositoryEditBasicController.php

177 lines
5.1 KiB
PHP
Raw Normal View History

<?php
final class DiffusionRepositoryEditBasicController
extends DiffusionRepositoryEditController {
protected function processDiffusionRequest(AphrontRequest $request) {
$user = $request->getUser();
$drequest = $this->diffusionRequest;
$repository = $drequest->getRepository();
$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();
}
$edit_uri = $this->getRepositoryControllerURI($repository, 'edit/');
$v_name = $repository->getName();
$v_desc = $repository->getDetail('description');
$v_clone_name = $repository->getDetail('clone-name');
$e_name = true;
$errors = array();
if ($request->isFormPost()) {
$v_name = $request->getStr('name');
$v_desc = $request->getStr('description');
$v_projects = $request->getArr('projectPHIDs');
if ($repository->isHosted()) {
$v_clone_name = $request->getStr('cloneName');
}
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;
$type_edge = PhabricatorTransactions::TYPE_EDGE;
$type_clone_name = PhabricatorRepositoryTransaction::TYPE_CLONE_NAME;
$xactions[] = id(clone $template)
->setTransactionType($type_name)
->setNewValue($v_name);
$xactions[] = id(clone $template)
->setTransactionType($type_desc)
->setNewValue($v_desc);
$xactions[] = id(clone $template)
->setTransactionType($type_clone_name)
->setNewValue($v_clone_name);
$xactions[] = id(clone $template)
->setTransactionType($type_edge)
->setMetadataValue(
'edge:type',
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST)
->setNewValue(
array(
'=' => array_fuse($v_projects),
));
id(new PhabricatorRepositoryEditor())
->setContinueOnNoEffect(true)
->setContentSourceFromRequest($request)
->setActor($user)
->applyTransactions($repository, $xactions);
return id(new AphrontRedirectResponse())->setURI($edit_uri);
}
}
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb(pht('Edit Basics'));
$title = pht('Edit %s', $repository->getName());
$form = id(new AphrontFormView())
->setUser($user)
->appendChild(
id(new AphrontFormTextControl())
->setName('name')
->setLabel(pht('Name'))
->setValue($v_name)
->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
->appendChild(
id(new PhabricatorRemarkupControl())
->setUser($user)
->setName('description')
->setLabel(pht('Description'))
->setValue($v_desc))
Convert all tokenizers to take token/scalar inputs Summary: Ref T7689. Ref T4100. This advances the goals of removing `loadViewerHandles()` (only 67 callsites remain!) and letting tokenizers some day take token functions like `viewer()` and `members(differential)`. Test Plan: - Sent a new message; used "To". - I simplified the cancel URI construction slightly because it's moot in all normal cases. - Edited a thread; used "Add Participants". - Searched rooms; used "Participants". - Searched countdowns; used "Authors". - Created a diff; used "Repository". - Edited a revision; edited "Projects"; edited "Reveiwers"; edited "Subscribers". - Searched for revisions; edited "responsible users"; "authors"; "reviwers"; "subscribers"; "repositories". - Added revision comments; edited "Add Reveiwers"; "Add Subscribers". - Commented on a commit; edited "Add Auditors"; "Add subscribers". - Edited a commit; edited "Projects". - Edited a repository; edited "Projects". - Searched feed, used "include Users"; "include Proejcts". - Searched files, used "authors". - Edited initiative; edited "Projects". - Searched backers; used "Backers". - Searched initiatives; used "Owners". - Edited build plans; edited "Run Command". - Searched Herald; used "Authors". - Added signature exemption in Legalpad. - Searhced legalpad; used "creators"; used "contributors". - Searched signatures; used "documents"; used "signers". - Created meme. - Searched macros; used "Authors". - Used "Projects" in Maniphest reports. - Used Maniphest comment actions. - Edited Maniphest tasks; edited "Assigned To"; edited "CC"; edited "projects". - Used "parent" in Maniphest task creation workflow. - Searched for projects; used "assigned to"; "in any projec"; "in all projects"; "not in projects"; "in users' projects"; "authors"; "subscribers". - Edited Maniphest bug filing domains, used "Default Author". - Searched for OAuth applications, used "Creators". - Edited Owners pacakge; edited "Primary Owner"; edited "Owners". - Searched for Owners packages; used "Owner". - OMG this UI is OLD - Edited a paste; edited "Projects". - Searched for paste; used "Authors". - Searched user activity log; used "Actors"; used "Users". - Edited a mock; edited "Projects"; edited "CC". - Searched for mocks; used "Authors". - Edited Phortune account; edited "Members". - Edited Phortune merchant account; edited "Members". - Searched Phrequent; used "Users". - Edited Ponder question; sued "projects". - Searched Ponder; used "Authors"; used "Answered By". - Added project members. - Searched for projects; used "Members". - Edited a Releeph product; edited "Pushers". - Searched pull requests; searched "Requestors". - Edited an arcanist project; used "Uses Symbols From". - Searhced push logs; used "Repositories"; used "Pushers". - Searched repositories; used "In nay project". - Used global search; used Authors/owners/Subscribers/In Any Project. - Edited a slowvote; used "Projects". - Searched slovotes; used "Authors". - Created a custom "Users" field; edited and searched for it. - Made a whole lot of typos in this list. ^^^^^^ Did not test: - Lint is nontrivial to test locally, I'll test it in production. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T4100, T7689 Differential Revision: https://secure.phabricator.com/D12224
2015-03-31 23:10:55 +02:00
->appendControl(
id(new AphrontFormTokenizerControl())
->setDatasource(new PhabricatorProjectDatasource())
->setName('projectPHIDs')
->setLabel(pht('Projects'))
Convert all tokenizers to take token/scalar inputs Summary: Ref T7689. Ref T4100. This advances the goals of removing `loadViewerHandles()` (only 67 callsites remain!) and letting tokenizers some day take token functions like `viewer()` and `members(differential)`. Test Plan: - Sent a new message; used "To". - I simplified the cancel URI construction slightly because it's moot in all normal cases. - Edited a thread; used "Add Participants". - Searched rooms; used "Participants". - Searched countdowns; used "Authors". - Created a diff; used "Repository". - Edited a revision; edited "Projects"; edited "Reveiwers"; edited "Subscribers". - Searched for revisions; edited "responsible users"; "authors"; "reviwers"; "subscribers"; "repositories". - Added revision comments; edited "Add Reveiwers"; "Add Subscribers". - Commented on a commit; edited "Add Auditors"; "Add subscribers". - Edited a commit; edited "Projects". - Edited a repository; edited "Projects". - Searched feed, used "include Users"; "include Proejcts". - Searched files, used "authors". - Edited initiative; edited "Projects". - Searched backers; used "Backers". - Searched initiatives; used "Owners". - Edited build plans; edited "Run Command". - Searched Herald; used "Authors". - Added signature exemption in Legalpad. - Searhced legalpad; used "creators"; used "contributors". - Searched signatures; used "documents"; used "signers". - Created meme. - Searched macros; used "Authors". - Used "Projects" in Maniphest reports. - Used Maniphest comment actions. - Edited Maniphest tasks; edited "Assigned To"; edited "CC"; edited "projects". - Used "parent" in Maniphest task creation workflow. - Searched for projects; used "assigned to"; "in any projec"; "in all projects"; "not in projects"; "in users' projects"; "authors"; "subscribers". - Edited Maniphest bug filing domains, used "Default Author". - Searched for OAuth applications, used "Creators". - Edited Owners pacakge; edited "Primary Owner"; edited "Owners". - Searched for Owners packages; used "Owner". - OMG this UI is OLD - Edited a paste; edited "Projects". - Searched for paste; used "Authors". - Searched user activity log; used "Actors"; used "Users". - Edited a mock; edited "Projects"; edited "CC". - Searched for mocks; used "Authors". - Edited Phortune account; edited "Members". - Edited Phortune merchant account; edited "Members". - Searched Phrequent; used "Users". - Edited Ponder question; sued "projects". - Searched Ponder; used "Authors"; used "Answered By". - Added project members. - Searched for projects; used "Members". - Edited a Releeph product; edited "Pushers". - Searched pull requests; searched "Requestors". - Edited an arcanist project; used "Uses Symbols From". - Searhced push logs; used "Repositories"; used "Pushers". - Searched repositories; used "In nay project". - Used global search; used Authors/owners/Subscribers/In Any Project. - Edited a slowvote; used "Projects". - Searched slovotes; used "Authors". - Created a custom "Users" field; edited and searched for it. - Made a whole lot of typos in this list. ^^^^^^ Did not test: - Lint is nontrivial to test locally, I'll test it in production. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T4100, T7689 Differential Revision: https://secure.phabricator.com/D12224
2015-03-31 23:10:55 +02:00
->setValue($repository->getProjectPHIDs()))
->appendChild(
id(new AphrontFormSubmitControl())
->setValue(pht('Save'))
->addCancelButton($edit_uri))
->appendChild(id(new PHUIFormDividerControl()))
->appendRemarkupInstructions($this->getReadmeInstructions());
$object_box = id(new PHUIObjectBoxView())
->setHeaderText($title)
->setForm($form)
->setFormErrors($errors);
return $this->buildApplicationPage(
array(
$crumbs,
$object_box,
),
array(
'title' => $title,
));
}
private function getReadmeInstructions() {
return pht(<<<EOTEXT
You can also create a `%s` file at the repository root (or in any
subdirectory) to provide information about the repository. These formats are
supported:
| File Name | Rendered As... |
|-----------|-----------------|
| `%s` | Plain Text |
| `%s` | Plain Text |
| `%s` | Remarkup |
| `%s` | Remarkup |
| `%s` | \xC2\xA1Fiesta! |
EOTEXT
,
'README',
'README',
'README.txt',
'README.remarkup',
'README.md',
'README.rainbow');
}
}