2015-10-14 00:46:12 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class DifferentialRevisionOperationController
|
|
|
|
extends DifferentialController {
|
|
|
|
|
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
$id = $request->getURIData('id');
|
|
|
|
|
|
|
|
$revision = id(new DifferentialRevisionQuery())
|
|
|
|
->withIDs(array($id))
|
|
|
|
->setViewer($viewer)
|
2015-10-14 00:46:30 +02:00
|
|
|
->needActiveDiffs(true)
|
2015-10-14 00:46:12 +02:00
|
|
|
->executeOne();
|
|
|
|
if (!$revision) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$detail_uri = "/D{$id}";
|
|
|
|
|
2015-10-26 20:58:37 +01:00
|
|
|
$op = new DrydockLandRepositoryOperation();
|
2015-10-27 19:51:59 +01:00
|
|
|
$barrier = $op->getBarrierToLanding($viewer, $revision);
|
|
|
|
if ($barrier) {
|
|
|
|
return $this->newDialog()
|
|
|
|
->setTitle($barrier['title'])
|
|
|
|
->appendParagraph($barrier['body'])
|
|
|
|
->addCancelButton($detail_uri);
|
2015-10-26 20:58:37 +01:00
|
|
|
}
|
|
|
|
|
2015-12-10 22:35:30 +01:00
|
|
|
$diff = $revision->getActiveDiff();
|
|
|
|
$repository = $revision->getRepository();
|
|
|
|
|
|
|
|
$ref_types = array(
|
|
|
|
PhabricatorRepositoryRefCursor::TYPE_BRANCH,
|
|
|
|
);
|
|
|
|
|
|
|
|
$e_ref = true;
|
|
|
|
|
|
|
|
$errors = array();
|
2015-10-14 00:46:12 +02:00
|
|
|
if ($request->isFormPost()) {
|
2015-10-14 00:46:30 +02:00
|
|
|
|
2015-12-10 22:35:30 +01:00
|
|
|
$ref_phid = head($request->getArr('refPHIDs'));
|
|
|
|
if (!strlen($ref_phid)) {
|
|
|
|
$e_ref = pht('Required');
|
|
|
|
$errors[] = pht(
|
|
|
|
'You must select a branch to land this revision onto.');
|
|
|
|
} else {
|
|
|
|
$ref = id(new PhabricatorRepositoryRefCursorQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withPHIDs(array($ref_phid))
|
|
|
|
->withRepositoryPHIDs(array($repository->getPHID()))
|
|
|
|
->withRefTypes($ref_types)
|
|
|
|
->executeOne();
|
|
|
|
if (!$ref) {
|
|
|
|
$e_ref = pht('Invalid');
|
|
|
|
$errors[] = pht(
|
|
|
|
'You must select a branch from this repository to land this '.
|
|
|
|
'revision onto.');
|
|
|
|
}
|
|
|
|
}
|
2015-10-14 00:46:30 +02:00
|
|
|
|
2015-12-10 22:35:30 +01:00
|
|
|
if (!$errors) {
|
|
|
|
// NOTE: The operation is locked to the current active diff, so if the
|
|
|
|
// revision is updated before the operation applies nothing sneaky
|
|
|
|
// occurs.
|
2015-10-14 00:46:12 +02:00
|
|
|
|
2015-12-10 22:35:30 +01:00
|
|
|
$target = 'branch:'.$ref->getRefName();
|
2015-10-14 00:46:12 +02:00
|
|
|
|
2015-12-10 22:35:30 +01:00
|
|
|
$operation = DrydockRepositoryOperation::initializeNewOperation($op)
|
|
|
|
->setAuthorPHID($viewer->getPHID())
|
|
|
|
->setObjectPHID($revision->getPHID())
|
|
|
|
->setRepositoryPHID($repository->getPHID())
|
|
|
|
->setRepositoryTarget($target)
|
|
|
|
->setProperty('differential.diffPHID', $diff->getPHID());
|
|
|
|
|
|
|
|
$operation->save();
|
|
|
|
$operation->scheduleUpdate();
|
|
|
|
|
|
|
|
return id(new AphrontRedirectResponse())
|
|
|
|
->setURI($detail_uri);
|
|
|
|
}
|
2015-10-14 00:46:12 +02:00
|
|
|
}
|
|
|
|
|
2015-12-10 22:35:30 +01:00
|
|
|
$ref_datasource = id(new DiffusionRefDatasource())
|
|
|
|
->setParameters(
|
|
|
|
array(
|
|
|
|
'repositoryPHIDs' => array($repository->getPHID()),
|
|
|
|
'refTypes' => $ref_types,
|
|
|
|
));
|
|
|
|
|
|
|
|
$form = id(new AphrontFormView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->appendRemarkupInstructions(
|
2015-10-14 00:46:12 +02:00
|
|
|
pht(
|
|
|
|
'In theory, this will do approximately what `arc land` would do. '.
|
2015-12-10 22:35:30 +01:00
|
|
|
'In practice, you will have a riveting adventure instead.'))
|
|
|
|
->appendControl(
|
|
|
|
id(new AphrontFormTokenizerControl())
|
|
|
|
->setLabel(pht('Onto Branch'))
|
|
|
|
->setName('refPHIDs')
|
|
|
|
->setLimit(1)
|
|
|
|
->setError($e_ref)
|
|
|
|
->setDatasource($ref_datasource))
|
|
|
|
->appendRemarkupInstructions(
|
2015-10-14 00:46:12 +02:00
|
|
|
pht(
|
2015-12-10 22:35:30 +01:00
|
|
|
'(WARNING) THIS FEATURE IS EXPERIMENTAL AND DANGEROUS! USE IT AT '.
|
|
|
|
'YOUR OWN RISK!'));
|
|
|
|
|
|
|
|
return $this->newDialog()
|
|
|
|
->setWidth(AphrontDialogView::WIDTH_FORM)
|
|
|
|
->setTitle(pht('Land Revision'))
|
|
|
|
->setErrors($errors)
|
|
|
|
->appendForm($form)
|
2015-10-14 00:46:12 +02:00
|
|
|
->addCancelButton($detail_uri)
|
|
|
|
->addSubmitButton(pht('Mutate Repository Unpredictably'));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|