diff --git a/src/applications/phriction/controller/PhrictionDeleteController.php b/src/applications/phriction/controller/PhrictionDeleteController.php --- a/src/applications/phriction/controller/PhrictionDeleteController.php +++ b/src/applications/phriction/controller/PhrictionDeleteController.php @@ -26,20 +26,10 @@ return new Aphront404Response(); } - $e_text = null; - $disallowed_states = array( - PhrictionDocumentStatus::STATUS_DELETED => true, // Silly - PhrictionDocumentStatus::STATUS_MOVED => true, // Makes no sense - PhrictionDocumentStatus::STATUS_STUB => true, // How could they? - ); - if (isset($disallowed_states[$document->getStatus()])) { - $e_text = pht( - 'An already moved or deleted document can not be deleted.'); - } - $document_uri = PhrictionDocument::getSlugURI($document->getSlug()); - if (!$e_text && $request->isFormPost()) { + $e_text = null; + if ($request->isFormPost()) { $xactions = array(); $xactions[] = id(new PhrictionTransaction()) ->setTransactionType(PhrictionTransaction::TYPE_DELETE) @@ -48,16 +38,19 @@ $editor = id(new PhrictionTransactionEditor()) ->setActor($user) ->setContentSourceFromRequest($request) - ->setContinueOnNoEffect(true) - ->applyTransactions($document, $xactions); - - return id(new AphrontRedirectResponse())->setURI($document_uri); + ->setContinueOnNoEffect(true); + try { + $editor->applyTransactions($document, $xactions); + return id(new AphrontRedirectResponse())->setURI($document_uri); + } catch (PhabricatorApplicationTransactionValidationException $ex) { + $e_text = phutil_implode_html("\n", $ex->getErrorMessages()); + } } if ($e_text) { $dialog = id(new AphrontDialogView()) ->setUser($user) - ->setTitle(pht('Can not delete document!')) + ->setTitle(pht('Can Not Delete Document!')) ->appendChild($e_text) ->addCancelButton($document_uri); } else { diff --git a/src/applications/phriction/editor/PhrictionTransactionEditor.php b/src/applications/phriction/editor/PhrictionTransactionEditor.php --- a/src/applications/phriction/editor/PhrictionTransactionEditor.php +++ b/src/applications/phriction/editor/PhrictionTransactionEditor.php @@ -477,6 +477,29 @@ } } break; + case PhrictionTransaction::TYPE_DELETE: + switch ($object->getStatus()) { + case PhrictionDocumentStatus::STATUS_DELETED: + $e_text = pht('An already deleted document can not be deleted.'); + break; + case PhrictionDocumentStatus::STATUS_MOVED: + $e_text = pht('A moved document can not be deleted.'); + break; + case PhrictionDocumentStatus::STATUS_STUB: + $e_text = pht('A stub document can not be deleted.'); + break; + default: + break 2; + } + + $error = new PhabricatorApplicationTransactionValidationError( + $type, + pht('Can not delete document.'), + $e_text, + $xaction); + $errors[] = $error; + + break; } }