@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<?php
2
3final 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}