@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at recaptime-dev/main 144 lines 3.7 kB view raw
1<?php 2 3final class PhabricatorApplicationTransactionWarningResponse 4 extends AphrontProxyResponse { 5 6 private $viewer; 7 private $object; 8 private $exception; 9 private $cancelURI; 10 11 public function setObject($object) { 12 $this->object = $object; 13 return $this; 14 } 15 16 public function getObject() { 17 return $this->object; 18 } 19 20 public function setCancelURI($cancel_uri) { 21 $this->cancelURI = $cancel_uri; 22 return $this; 23 } 24 25 public function setException( 26 PhabricatorApplicationTransactionWarningException $exception) { 27 $this->exception = $exception; 28 return $this; 29 } 30 31 public function getException() { 32 return $this->exception; 33 } 34 35 protected function buildProxy() { 36 return new AphrontDialogResponse(); 37 } 38 39 public function reduceProxyResponse() { 40 $request = $this->getRequest(); 41 $viewer = $request->getViewer(); 42 $object = $this->getObject(); 43 44 $xactions = $this->getException()->getTransactions(); 45 $xaction_groups = mgroup($xactions, 'getTransactionType'); 46 47 $warnings = array(); 48 foreach ($xaction_groups as $xaction_group) { 49 $xaction = head($xaction_group); 50 51 $warning = $xaction->newWarningForTransactions( 52 $object, 53 $xaction_group); 54 55 if (!($warning instanceof PhabricatorTransactionWarning)) { 56 throw new Exception( 57 pht( 58 'Expected "newTransactionWarning()" to return an object of '. 59 'class "PhabricatorTransactionWarning", got something else '. 60 '("%s") from transaction of class "%s".', 61 phutil_describe_type($warning), 62 get_class($xaction))); 63 } 64 65 $warnings[] = $warning; 66 } 67 68 $dialog = id(new AphrontDialogView()) 69 ->setViewer($viewer); 70 71 $last_key = last_key($warnings); 72 foreach ($warnings as $warning_key => $warning) { 73 $paragraphs = $warning->getWarningParagraphs(); 74 foreach ($paragraphs as $paragraph) { 75 $dialog->appendParagraph($paragraph); 76 } 77 78 if ($warning_key !== $last_key) { 79 $dialog->appendChild(phutil_tag('hr')); 80 } 81 } 82 83 $title_texts = array(); 84 $continue_texts = array(); 85 $cancel_texts = array(); 86 foreach ($warnings as $warning) { 87 $title_text = $warning->getTitleText(); 88 if ($title_text !== null) { 89 $title_texts[] = $title_text; 90 } 91 92 $continue_text = $warning->getContinueActionText(); 93 if ($continue_text !== null) { 94 $continue_texts[] = $continue_text; 95 } 96 97 $cancel_text = $warning->getCancelActionText(); 98 if ($cancel_text !== null) { 99 $cancel_texts[] = $cancel_text; 100 } 101 } 102 103 $title_texts = array_unique($title_texts); 104 if (count($title_texts) === 1) { 105 $title = head($title_texts); 106 } else { 107 $title = pht('Warnings'); 108 } 109 110 $continue_texts = array_unique($continue_texts); 111 if (count($continue_texts) === 1) { 112 $continue_action = head($continue_texts); 113 } else { 114 $continue_action = pht('Continue'); 115 } 116 117 $cancel_texts = array_unique($cancel_texts); 118 if (count($cancel_texts) === 1) { 119 $cancel_action = head($cancel_texts); 120 } else { 121 $cancel_action = null; 122 } 123 124 $dialog 125 ->setTitle($title) 126 ->addSubmitButton($continue_action); 127 128 if ($cancel_action === null) { 129 $dialog->addCancelButton($this->cancelURI); 130 } else { 131 $dialog->addCancelButton($this->cancelURI, $cancel_action); 132 } 133 134 $passthrough = $request->getPassthroughRequestParameters(); 135 foreach ($passthrough as $key => $value) { 136 $dialog->addHiddenInput($key, $value); 137 } 138 139 $dialog->addHiddenInput('editEngine.warnings', 1); 140 141 return $this->getProxy()->setDialog($dialog); 142 } 143 144}