2011-12-17 09:19:08 -08:00
|
|
|
<?php
|
|
|
|
|
2012-03-09 15:46:25 -08:00
|
|
|
final class PhrictionDeleteController extends PhrictionController {
|
2011-12-17 09:19:08 -08:00
|
|
|
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->id = $data['id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
2014-05-19 12:41:12 -07:00
|
|
|
$document = id(new PhrictionDocumentQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withIDs(array($this->id))
|
2014-11-05 12:37:53 -08:00
|
|
|
->needContent(true)
|
2014-05-19 12:41:12 -07:00
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
))
|
|
|
|
->executeOne();
|
2011-12-17 09:19:08 -08:00
|
|
|
if (!$document) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$document_uri = PhrictionDocument::getSlugURI($document->getSlug());
|
|
|
|
|
2014-11-07 10:03:20 -08:00
|
|
|
$e_text = null;
|
|
|
|
if ($request->isFormPost()) {
|
2014-11-05 12:37:53 -08:00
|
|
|
$xactions = array();
|
|
|
|
$xactions[] = id(new PhrictionTransaction())
|
|
|
|
->setTransactionType(PhrictionTransaction::TYPE_DELETE)
|
|
|
|
->setNewValue(true);
|
|
|
|
|
|
|
|
$editor = id(new PhrictionTransactionEditor())
|
2012-10-10 10:18:23 -07:00
|
|
|
->setActor($user)
|
2014-11-05 12:37:53 -08:00
|
|
|
->setContentSourceFromRequest($request)
|
2014-11-07 10:03:20 -08:00
|
|
|
->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());
|
|
|
|
}
|
2011-12-17 09:19:08 -08:00
|
|
|
}
|
|
|
|
|
2013-03-13 10:30:39 -07:00
|
|
|
if ($e_text) {
|
2013-03-04 08:50:42 -08:00
|
|
|
$dialog = id(new AphrontDialogView())
|
|
|
|
->setUser($user)
|
2014-11-07 10:03:20 -08:00
|
|
|
->setTitle(pht('Can Not Delete Document!'))
|
2013-03-13 10:30:39 -07:00
|
|
|
->appendChild($e_text)
|
2013-03-04 08:50:42 -08:00
|
|
|
->addCancelButton($document_uri);
|
|
|
|
} else {
|
|
|
|
$dialog = id(new AphrontDialogView())
|
|
|
|
->setUser($user)
|
2013-04-09 15:50:48 -07:00
|
|
|
->setTitle(pht('Delete Document?'))
|
2013-03-04 08:50:42 -08:00
|
|
|
->appendChild(
|
|
|
|
pht('Really delete this document? You can recover it later by '.
|
|
|
|
'reverting to a previous version.'))
|
|
|
|
->addSubmitButton(pht('Delete'))
|
|
|
|
->addCancelButton($document_uri);
|
|
|
|
}
|
2011-12-17 09:19:08 -08:00
|
|
|
|
|
|
|
return id(new AphrontDialogResponse())->setDialog($dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|