Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phriction/controller/PhrictionDeleteController.php
Show All 9 Lines | final class PhrictionDeleteController extends PhrictionController { | ||||
public function processRequest() { | public function processRequest() { | ||||
$request = $this->getRequest(); | $request = $this->getRequest(); | ||||
$user = $request->getUser(); | $user = $request->getUser(); | ||||
$document = id(new PhrictionDocumentQuery()) | $document = id(new PhrictionDocumentQuery()) | ||||
->setViewer($user) | ->setViewer($user) | ||||
->withIDs(array($this->id)) | ->withIDs(array($this->id)) | ||||
->needContent(true) | |||||
->requireCapabilities( | ->requireCapabilities( | ||||
array( | array( | ||||
PhabricatorPolicyCapability::CAN_EDIT, | PhabricatorPolicyCapability::CAN_EDIT, | ||||
PhabricatorPolicyCapability::CAN_VIEW, | PhabricatorPolicyCapability::CAN_VIEW, | ||||
)) | )) | ||||
->executeOne(); | ->executeOne(); | ||||
if (!$document) { | if (!$document) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
$e_text = null; | $e_text = null; | ||||
$disallowed_states = array( | $disallowed_states = array( | ||||
PhrictionDocumentStatus::STATUS_DELETED => true, // Silly | PhrictionDocumentStatus::STATUS_DELETED => true, // Silly | ||||
PhrictionDocumentStatus::STATUS_MOVED => true, // Makes no sense | PhrictionDocumentStatus::STATUS_MOVED => true, // Makes no sense | ||||
PhrictionDocumentStatus::STATUS_STUB => true, // How could they? | PhrictionDocumentStatus::STATUS_STUB => true, // How could they? | ||||
); | ); | ||||
if (isset($disallowed_states[$document->getStatus()])) { | if (isset($disallowed_states[$document->getStatus()])) { | ||||
$e_text = pht('An already moved or deleted document can not be deleted'); | $e_text = pht( | ||||
'An already moved or deleted document can not be deleted.'); | |||||
} | } | ||||
$document_uri = PhrictionDocument::getSlugURI($document->getSlug()); | $document_uri = PhrictionDocument::getSlugURI($document->getSlug()); | ||||
if (!$e_text && $request->isFormPost()) { | if (!$e_text && $request->isFormPost()) { | ||||
$editor = id(PhrictionDocumentEditor::newForSlug($document->getSlug())) | $xactions = array(); | ||||
$xactions[] = id(new PhrictionTransaction()) | |||||
->setTransactionType(PhrictionTransaction::TYPE_DELETE) | |||||
->setNewValue(true); | |||||
$editor = id(new PhrictionTransactionEditor()) | |||||
->setActor($user) | ->setActor($user) | ||||
->delete(); | ->setContentSourceFromRequest($request) | ||||
->setContinueOnNoEffect(true) | |||||
->applyTransactions($document, $xactions); | |||||
return id(new AphrontRedirectResponse())->setURI($document_uri); | return id(new AphrontRedirectResponse())->setURI($document_uri); | ||||
} | } | ||||
if ($e_text) { | if ($e_text) { | ||||
$dialog = id(new AphrontDialogView()) | $dialog = id(new AphrontDialogView()) | ||||
->setUser($user) | ->setUser($user) | ||||
->setTitle(pht('Can not delete document!')) | ->setTitle(pht('Can not delete document!')) | ||||
->appendChild($e_text) | ->appendChild($e_text) | ||||
Show All 16 Lines |