2012-08-08 19:03:41 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class DiffusionCommitEditController extends DiffusionController {
|
|
|
|
|
2016-01-05 17:13:05 +01:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$response = $this->loadDiffusionContext();
|
|
|
|
if ($response) {
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
$drequest = $this->getDiffusionRequest();
|
2012-08-08 19:03:41 +02:00
|
|
|
$repository = $drequest->getRepository();
|
2016-01-05 17:13:05 +01:00
|
|
|
$commit = $drequest->loadCommit();
|
2012-08-08 19:03:41 +02:00
|
|
|
|
|
|
|
if (!$commit) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2016-01-05 17:13:05 +01:00
|
|
|
$data = $commit->loadCommitData();
|
|
|
|
$page_title = pht('Edit Diffusion Commit');
|
|
|
|
|
2015-03-31 23:10:55 +02:00
|
|
|
$commit_phid = $commit->getPHID();
|
|
|
|
$edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST;
|
2012-08-08 19:03:41 +02:00
|
|
|
$current_proj_phids = PhabricatorEdgeQuery::loadDestinationPHIDs(
|
|
|
|
$commit_phid,
|
2013-02-19 22:33:10 +01:00
|
|
|
$edge_type);
|
2012-08-08 19:03:41 +02:00
|
|
|
|
|
|
|
if ($request->isFormPost()) {
|
2014-11-19 23:43:59 +01:00
|
|
|
$xactions = array();
|
2012-08-08 19:03:41 +02:00
|
|
|
$proj_phids = $request->getArr('projects');
|
2014-11-19 23:43:59 +01:00
|
|
|
$xactions[] = id(new PhabricatorAuditTransaction())
|
|
|
|
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
|
|
|
|
->setMetadataValue('edge:type', $edge_type)
|
|
|
|
->setNewValue(array('=' => array_fuse($proj_phids)));
|
2016-01-05 17:13:05 +01:00
|
|
|
|
2014-11-19 23:43:59 +01:00
|
|
|
$editor = id(new PhabricatorAuditEditor())
|
2016-01-05 17:13:05 +01:00
|
|
|
->setActor($viewer)
|
2014-11-19 23:43:59 +01:00
|
|
|
->setContinueOnNoEffect(true)
|
|
|
|
->setContentSourceFromRequest($request);
|
2016-01-05 17:13:05 +01:00
|
|
|
|
|
|
|
$editor->applyTransactions($commit, $xactions);
|
|
|
|
|
2012-08-08 19:03:41 +02:00
|
|
|
return id(new AphrontRedirectResponse())
|
2016-01-02 20:28:31 +01:00
|
|
|
->setURI($commit->getURI());
|
2012-08-08 19:03:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$tokenizer_id = celerity_generate_unique_node_id();
|
2014-08-26 01:14:19 +02:00
|
|
|
$form = id(new AphrontFormView())
|
2016-01-05 17:13:05 +01:00
|
|
|
->setUser($viewer)
|
2012-08-08 19:03:41 +02:00
|
|
|
->setAction($request->getRequestURI()->getPath())
|
2015-03-31 23:10:55 +02:00
|
|
|
->appendControl(
|
2012-08-08 19:03:41 +02:00
|
|
|
id(new AphrontFormTokenizerControl())
|
2013-05-11 17:23:19 +02:00
|
|
|
->setLabel(pht('Projects'))
|
2012-08-08 19:03:41 +02:00
|
|
|
->setName('projects')
|
2015-03-31 23:10:55 +02:00
|
|
|
->setValue($current_proj_phids)
|
2012-08-08 19:03:41 +02:00
|
|
|
->setID($tokenizer_id)
|
2014-07-11 02:28:29 +02:00
|
|
|
->setDatasource(new PhabricatorProjectDatasource()));
|
2012-08-08 19:03:41 +02:00
|
|
|
|
2014-08-26 01:14:19 +02:00
|
|
|
$reason = $data->getCommitDetail('autocloseReason', false);
|
2015-01-06 20:42:15 +01:00
|
|
|
$reason = PhabricatorRepository::BECAUSE_AUTOCLOSE_FORCED;
|
2014-08-26 01:14:19 +02:00
|
|
|
if ($reason !== false) {
|
|
|
|
switch ($reason) {
|
|
|
|
case PhabricatorRepository::BECAUSE_REPOSITORY_IMPORTING:
|
|
|
|
$desc = pht('No, Repository Importing');
|
|
|
|
break;
|
|
|
|
case PhabricatorRepository::BECAUSE_AUTOCLOSE_DISABLED:
|
|
|
|
$desc = pht('No, Autoclose Disabled');
|
|
|
|
break;
|
|
|
|
case PhabricatorRepository::BECAUSE_NOT_ON_AUTOCLOSE_BRANCH:
|
|
|
|
$desc = pht('No, Not On Autoclose Branch');
|
|
|
|
break;
|
2015-01-06 20:42:15 +01:00
|
|
|
case PhabricatorRepository::BECAUSE_AUTOCLOSE_FORCED:
|
|
|
|
$desc = pht('Yes, Forced Via bin/repository CLI Tool.');
|
|
|
|
break;
|
2014-08-26 01:14:19 +02:00
|
|
|
case null:
|
|
|
|
$desc = pht('Yes');
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$desc = pht('Unknown');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$doc_href = PhabricatorEnv::getDoclink('Diffusion User Guide: Autoclose');
|
|
|
|
$doc_link = phutil_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => $doc_href,
|
|
|
|
'target' => '_blank',
|
|
|
|
),
|
|
|
|
pht('Learn More'));
|
|
|
|
|
|
|
|
$form->appendChild(
|
|
|
|
id(new AphrontFormMarkupControl())
|
|
|
|
->setLabel(pht('Autoclose?'))
|
|
|
|
->setValue(array($desc, " \xC2\xB7 ", $doc_link)));
|
|
|
|
}
|
|
|
|
|
2016-01-05 17:13:05 +01:00
|
|
|
$form->appendControl(
|
|
|
|
id(new AphrontFormSubmitControl())
|
|
|
|
->setValue(pht('Save'))
|
|
|
|
->addCancelButton($commit->getURI()));
|
2014-08-26 01:14:19 +02:00
|
|
|
|
2016-01-05 17:13:05 +01:00
|
|
|
$crumbs = $this->buildCrumbs(
|
|
|
|
array(
|
|
|
|
'commit' => true,
|
|
|
|
));
|
2014-08-26 01:14:19 +02:00
|
|
|
$crumbs->addTextCrumb(pht('Edit'));
|
|
|
|
|
2013-09-25 20:23:29 +02:00
|
|
|
$form_box = id(new PHUIObjectBoxView())
|
2013-08-27 00:45:58 +02:00
|
|
|
->setHeaderText($page_title)
|
|
|
|
->setForm($form);
|
2012-08-08 19:03:41 +02:00
|
|
|
|
2016-01-05 17:13:05 +01:00
|
|
|
return $this->newPage()
|
|
|
|
->setTitle($page_title)
|
|
|
|
->setCrumbs($crumbs)
|
|
|
|
->appendChild($form_box);
|
2012-08-08 19:03:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|