@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 upstream/main 65 lines 2.1 kB view raw
1<?php 2 3final class PhrictionDeleteController extends PhrictionController { 4 5 public function handleRequest(AphrontRequest $request) { 6 $viewer = $request->getViewer(); 7 $id = $request->getURIData('id'); 8 9 $document = id(new PhrictionDocumentQuery()) 10 ->setViewer($viewer) 11 ->withIDs(array($id)) 12 ->needContent(true) 13 ->requireCapabilities( 14 array( 15 PhabricatorPolicyCapability::CAN_EDIT, 16 PhabricatorPolicyCapability::CAN_VIEW, 17 )) 18 ->executeOne(); 19 if (!$document) { 20 return new Aphront404Response(); 21 } 22 23 $document_uri = PhrictionDocument::getSlugURI($document->getSlug()); 24 25 $e_text = null; 26 if ($request->isFormPost()) { 27 $xactions = array(); 28 $xactions[] = id(new PhrictionTransaction()) 29 ->setTransactionType( 30 PhrictionDocumentDeleteTransaction::TRANSACTIONTYPE) 31 ->setNewValue(true); 32 33 $editor = id(new PhrictionTransactionEditor()) 34 ->setActor($viewer) 35 ->setContentSourceFromRequest($request) 36 ->setContinueOnNoEffect(true); 37 try { 38 $editor->applyTransactions($document, $xactions); 39 return id(new AphrontRedirectResponse())->setURI($document_uri); 40 } catch (PhabricatorApplicationTransactionValidationException $ex) { 41 $e_text = phutil_implode_html("\n", $ex->getErrorMessages()); 42 } 43 } 44 45 if ($e_text) { 46 $dialog = id(new AphrontDialogView()) 47 ->setUser($viewer) 48 ->setTitle(pht('Can Not Delete Document!')) 49 ->appendChild($e_text) 50 ->addCancelButton($document_uri); 51 } else { 52 $dialog = id(new AphrontDialogView()) 53 ->setUser($viewer) 54 ->setTitle(pht('Delete Document?')) 55 ->appendChild( 56 pht('Really delete this document? You can recover it later by '. 57 'reverting to a previous version.')) 58 ->addSubmitButton(pht('Delete')) 59 ->addCancelButton($document_uri); 60 } 61 62 return id(new AphrontDialogResponse())->setDialog($dialog); 63 } 64 65}