Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / almanac / controller / AlmanacPropertyDeleteController.php
blobf38670041b6e01f93fbad3d1ef926509fae8aa42
1 <?php
3 final class AlmanacPropertyDeleteController
4 extends AlmanacPropertyController {
6 public function handleRequest(AphrontRequest $request) {
7 $viewer = $request->getViewer();
9 $response = $this->loadPropertyObject();
10 if ($response) {
11 return $response;
14 $object = $this->getPropertyObject();
16 $key = $request->getStr('key');
17 if (!strlen($key)) {
18 return new Aphront404Response();
21 $cancel_uri = $object->getURI();
23 $builtins = $object->getAlmanacPropertyFieldSpecifications();
24 $is_builtin = isset($builtins[$key]);
26 if ($is_builtin) {
27 $title = pht('Reset Property');
28 $body = pht(
29 'Reset property "%s" to its default value?',
30 $key);
31 $submit_text = pht('Reset Property');
32 } else {
33 $title = pht('Delete Property');
34 $body = pht(
35 'Delete property "%s"?',
36 $key);
37 $submit_text = pht('Delete Property');
40 $validation_exception = null;
41 if ($request->isFormPost()) {
42 $xaction_type = $object->getAlmanacPropertyDeleteTransactionType();
44 $xaction = $object->getApplicationTransactionTemplate()
45 ->setTransactionType($xaction_type)
46 ->setMetadataValue('almanac.property', $key);
48 $editor = $object->getApplicationTransactionEditor()
49 ->setActor($viewer)
50 ->setContentSourceFromRequest($request)
51 ->setContinueOnNoEffect(true)
52 ->setContinueOnMissingFields(true);
54 try {
55 $editor->applyTransactions($object, array($xaction));
56 return id(new AphrontRedirectResponse())->setURI($cancel_uri);
57 } catch (PhabricatorApplicationTransactionValidationException $ex) {
58 $validation_exception = $ex;
62 return $this->newDialog()
63 ->setTitle($title)
64 ->setValidationException($validation_exception)
65 ->addHiddenInput('objectPHID', $object->getPHID())
66 ->addHiddenInput('key', $key)
67 ->appendParagraph($body)
68 ->addCancelButton($cancel_uri)
69 ->addSubmitButton($submit_text);