Differential D17020 Diff 41129 src/applications/release/controller/ReleaseChangeRequestActionController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/release/controller/ReleaseChangeRequestActionController.php
- This file was added.
<?php | |||||
final class ReleaseChangeRequestActionController extends PhabricatorController { | |||||
public function handleRequest(AphrontRequest $request) { | |||||
$viewer = $this->getViewer(); | |||||
$change_phid = $request->getURIData('phid'); | |||||
$change = id(new ReleaseChangeRequestQuery()) | |||||
->setViewer($viewer) | |||||
->withPHIDs(array($change_phid)) | |||||
->needReleases(true) | |||||
->needRequestObjects(true) | |||||
->executeOne(); | |||||
if (!$change) { | |||||
return new Aphront404Response(); | |||||
} | |||||
$release = $change->getRelease(); | |||||
$action_key = $request->getURIData('action'); | |||||
$action = ReleaseChangeRequestAction::getActionByKey($action_key); | |||||
$action->assertPolicy($viewer, $change); | |||||
$errors = array(); | |||||
if (!$action->isEnabledForRequest($change)) { | |||||
$errors[] = pht( | |||||
'This action can not be applied to this Change Request at this time.'); | |||||
} | |||||
if ($request->isDialogFormPost()) { | |||||
if (!$errors) { | |||||
try { | |||||
$redirect_uri = $action->act($change, $request); | |||||
return id(new AphrontRedirectResponse())->setURI($redirect_uri); | |||||
} catch (PhabricatorApplicationTransactionValidationException $ex) { | |||||
$errors[] = 'Failed to invoke action! '.$ex->getMessage(); | |||||
} | |||||
} | |||||
} | |||||
$prompt = $action->getPrompt($change); | |||||
$dialog = $this->newDialog() | |||||
->setSubmitURI($request->getRequestURI()) | |||||
->setTitle($action->getFormTitle($change)) | |||||
->appendChild($prompt) | |||||
->setErrors($errors) | |||||
->addCancelButton('#'); | |||||
if ($action->isEnabledForRequest($change)) { | |||||
$dialog->addSubmitButton(pht('Submit')); | |||||
} | |||||
return $dialog; | |||||
} | |||||
} |