Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/files/controller/PhabricatorFileDeleteController.php
12242 views
1
<?php
2
3
final class PhabricatorFileDeleteController extends PhabricatorFileController {
4
5
public function handleRequest(AphrontRequest $request) {
6
$viewer = $request->getViewer();
7
$id = $request->getURIData('id');
8
9
$file = id(new PhabricatorFileQuery())
10
->setViewer($viewer)
11
->withIDs(array($id))
12
->withIsDeleted(false)
13
->requireCapabilities(
14
array(
15
PhabricatorPolicyCapability::CAN_VIEW,
16
PhabricatorPolicyCapability::CAN_EDIT,
17
))
18
->executeOne();
19
if (!$file) {
20
return new Aphront404Response();
21
}
22
23
if (($viewer->getPHID() != $file->getAuthorPHID()) &&
24
(!$viewer->getIsAdmin())) {
25
return new Aphront403Response();
26
}
27
28
if ($request->isFormPost()) {
29
$xactions = array();
30
31
$xactions[] = id(new PhabricatorFileTransaction())
32
->setTransactionType(PhabricatorFileDeleteTransaction::TRANSACTIONTYPE)
33
->setNewValue(true);
34
35
id(new PhabricatorFileEditor())
36
->setActor($viewer)
37
->setContentSourceFromRequest($request)
38
->setContinueOnNoEffect(true)
39
->setContinueOnMissingFields(true)
40
->applyTransactions($file, $xactions);
41
42
return id(new AphrontRedirectResponse())->setURI('/file/');
43
}
44
45
return $this->newDialog()
46
->setTitle(pht('Really delete file?'))
47
->appendChild(hsprintf(
48
'<p>%s</p>',
49
pht(
50
'Permanently delete "%s"? This action can not be undone.',
51
$file->getName())))
52
->addSubmitButton(pht('Delete'))
53
->addCancelButton($file->getInfoURI());
54
}
55
}
56
57