@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
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Phriction - move delete business logic from controlller to editor

Summary: Ref T4029. More cleanup and code consolidation for the long terms benefits.

Test Plan: found a document and opened up two browser tabs. Loaded delete dialog on both. Completed delete in one tab and noted document was properly deleted. Tried to complete delete in tab 2 and got an error message.

Reviewers: chad, epriestley

Reviewed By: epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T4029

Differential Revision: https://secure.phabricator.com/D10809

+33 -17
+10 -17
src/applications/phriction/controller/PhrictionDeleteController.php
··· 26 26 return new Aphront404Response(); 27 27 } 28 28 29 - $e_text = null; 30 - $disallowed_states = array( 31 - PhrictionDocumentStatus::STATUS_DELETED => true, // Silly 32 - PhrictionDocumentStatus::STATUS_MOVED => true, // Makes no sense 33 - PhrictionDocumentStatus::STATUS_STUB => true, // How could they? 34 - ); 35 - if (isset($disallowed_states[$document->getStatus()])) { 36 - $e_text = pht( 37 - 'An already moved or deleted document can not be deleted.'); 38 - } 39 - 40 29 $document_uri = PhrictionDocument::getSlugURI($document->getSlug()); 41 30 42 - if (!$e_text && $request->isFormPost()) { 31 + $e_text = null; 32 + if ($request->isFormPost()) { 43 33 $xactions = array(); 44 34 $xactions[] = id(new PhrictionTransaction()) 45 35 ->setTransactionType(PhrictionTransaction::TYPE_DELETE) ··· 48 38 $editor = id(new PhrictionTransactionEditor()) 49 39 ->setActor($user) 50 40 ->setContentSourceFromRequest($request) 51 - ->setContinueOnNoEffect(true) 52 - ->applyTransactions($document, $xactions); 53 - 54 - return id(new AphrontRedirectResponse())->setURI($document_uri); 41 + ->setContinueOnNoEffect(true); 42 + try { 43 + $editor->applyTransactions($document, $xactions); 44 + return id(new AphrontRedirectResponse())->setURI($document_uri); 45 + } catch (PhabricatorApplicationTransactionValidationException $ex) { 46 + $e_text = phutil_implode_html("\n", $ex->getErrorMessages()); 47 + } 55 48 } 56 49 57 50 if ($e_text) { 58 51 $dialog = id(new AphrontDialogView()) 59 52 ->setUser($user) 60 - ->setTitle(pht('Can not delete document!')) 53 + ->setTitle(pht('Can Not Delete Document!')) 61 54 ->appendChild($e_text) 62 55 ->addCancelButton($document_uri); 63 56 } else {
+23
src/applications/phriction/editor/PhrictionTransactionEditor.php
··· 477 477 } 478 478 } 479 479 break; 480 + case PhrictionTransaction::TYPE_DELETE: 481 + switch ($object->getStatus()) { 482 + case PhrictionDocumentStatus::STATUS_DELETED: 483 + $e_text = pht('An already deleted document can not be deleted.'); 484 + break; 485 + case PhrictionDocumentStatus::STATUS_MOVED: 486 + $e_text = pht('A moved document can not be deleted.'); 487 + break; 488 + case PhrictionDocumentStatus::STATUS_STUB: 489 + $e_text = pht('A stub document can not be deleted.'); 490 + break; 491 + default: 492 + break 2; 493 + } 494 + 495 + $error = new PhabricatorApplicationTransactionValidationError( 496 + $type, 497 + pht('Can not delete document.'), 498 + $e_text, 499 + $xaction); 500 + $errors[] = $error; 501 + 502 + break; 480 503 } 481 504 } 482 505