Differential D21191 Diff 50524 src/applications/transactions/response/PhabricatorApplicationTransactionWarningResponse.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/transactions/response/PhabricatorApplicationTransactionWarningResponse.php
| <?php | <?php | ||||
| final class PhabricatorApplicationTransactionWarningResponse | final class PhabricatorApplicationTransactionWarningResponse | ||||
| extends AphrontProxyResponse { | extends AphrontProxyResponse { | ||||
| private $viewer; | private $viewer; | ||||
| private $object; | |||||
| private $exception; | private $exception; | ||||
| private $cancelURI; | private $cancelURI; | ||||
| public function setObject($object) { | |||||
| $this->object = $object; | |||||
| return $this; | |||||
| } | |||||
| public function getObject() { | |||||
| return $this->object; | |||||
| } | |||||
| public function setCancelURI($cancel_uri) { | public function setCancelURI($cancel_uri) { | ||||
| $this->cancelURI = $cancel_uri; | $this->cancelURI = $cancel_uri; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function setException( | public function setException( | ||||
| PhabricatorApplicationTransactionWarningException $exception) { | PhabricatorApplicationTransactionWarningException $exception) { | ||||
| $this->exception = $exception; | $this->exception = $exception; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getException() { | |||||
| return $this->exception; | |||||
| } | |||||
| protected function buildProxy() { | protected function buildProxy() { | ||||
| return new AphrontDialogResponse(); | return new AphrontDialogResponse(); | ||||
| } | } | ||||
| public function reduceProxyResponse() { | public function reduceProxyResponse() { | ||||
| $request = $this->getRequest(); | $request = $this->getRequest(); | ||||
| $viewer = $request->getViewer(); | |||||
| $object = $this->getObject(); | |||||
| $title = pht('Warning: Unexpected Effects'); | $xactions = $this->getException()->getTransactions(); | ||||
| $xaction_groups = mgroup($xactions, 'getTransactionType'); | |||||
| $head = pht( | $warnings = array(); | ||||
| 'This is a draft revision that will not publish any notifications '. | foreach ($xaction_groups as $xaction_group) { | ||||
| 'until the author requests review.'); | $xaction = head($xaction_group); | ||||
| $tail = pht( | |||||
| 'Mentioned or subscribed users will not be notified.'); | $warning = $xaction->newWarningForTransactions( | ||||
| $object, | |||||
| $xaction_group); | |||||
| if (!($warning instanceof PhabricatorTransactionWarning)) { | |||||
| throw new Exception( | |||||
| pht( | |||||
| 'Expected "newTransactionWarning()" to return an object of '. | |||||
| 'class "PhabricatorTransactionWarning", got something else '. | |||||
| '("%s") from transaction of class "%s".', | |||||
| phutil_describe_type($warning), | |||||
| get_class($xaction))); | |||||
| } | |||||
| $continue = pht('Tell No One'); | $warnings[] = $warning; | ||||
| } | |||||
| $dialog = id(new AphrontDialogView()) | $dialog = id(new AphrontDialogView()) | ||||
| ->setViewer($request->getViewer()) | ->setViewer($viewer); | ||||
| ->setTitle($title); | |||||
| $last_key = last_key($warnings); | |||||
| foreach ($warnings as $warning_key => $warning) { | |||||
| $paragraphs = $warning->getWarningParagraphs(); | |||||
| foreach ($paragraphs as $paragraph) { | |||||
| $dialog->appendParagraph($paragraph); | |||||
| } | |||||
| if ($warning_key !== $last_key) { | |||||
| $dialog->appendChild(phutil_tag('hr')); | |||||
| } | |||||
| } | |||||
| $dialog->appendParagraph($head); | $title_texts = array(); | ||||
| $dialog->appendParagraph($tail); | $continue_texts = array(); | ||||
| $cancel_texts = array(); | |||||
| foreach ($warnings as $warning) { | |||||
| $title_text = $warning->getTitleText(); | |||||
| if ($title_text !== null) { | |||||
| $title_texts[] = $title_text; | |||||
| } | |||||
| $continue_text = $warning->getContinueActionText(); | |||||
| if ($continue_text !== null) { | |||||
| $continue_texts[] = $continue_text; | |||||
| } | |||||
| $cancel_text = $warning->getCancelActionText(); | |||||
| if ($cancel_text !== null) { | |||||
| $cancel_texts[] = $cancel_text; | |||||
| } | |||||
| } | |||||
| $title_texts = array_unique($title_texts); | |||||
| if (count($title_texts) === 1) { | |||||
| $title = head($title_texts); | |||||
| } else { | |||||
| $title = pht('Warnings'); | |||||
| } | |||||
| $continue_texts = array_unique($continue_texts); | |||||
| if (count($continue_texts) === 1) { | |||||
| $continue_action = head($continue_texts); | |||||
| } else { | |||||
| $continue_action = pht('Continue'); | |||||
| } | |||||
| $cancel_texts = array_unique($cancel_texts); | |||||
| if (count($cancel_texts) === 1) { | |||||
| $cancel_action = head($cancel_texts); | |||||
| } else { | |||||
| $cancel_action = null; | |||||
| } | |||||
| $dialog | |||||
| ->setTitle($title) | |||||
| ->addSubmitButton($continue_action); | |||||
| if ($cancel_action === null) { | |||||
| $dialog->addCancelButton($this->cancelURI); | |||||
| } else { | |||||
| $dialog->addCancelButton($this->cancelURI, $cancel_action); | |||||
| } | |||||
| $passthrough = $request->getPassthroughRequestParameters(); | $passthrough = $request->getPassthroughRequestParameters(); | ||||
| foreach ($passthrough as $key => $value) { | foreach ($passthrough as $key => $value) { | ||||
| $dialog->addHiddenInput($key, $value); | $dialog->addHiddenInput($key, $value); | ||||
| } | } | ||||
| $dialog | $dialog->addHiddenInput('editEngine.warnings', 1); | ||||
| ->addHiddenInput('editEngine.warnings', 1) | |||||
| ->addSubmitButton($continue) | |||||
| ->addCancelButton($this->cancelURI); | |||||
| return $this->getProxy()->setDialog($dialog); | return $this->getProxy()->setDialog($dialog); | ||||
| } | } | ||||
| } | } | ||||