Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / files / controller / PhabricatorFileDeleteController.php
blobbe9cecfcf5c74cb83ede6e93e39e3ea1de2edb0b
1 <?php
3 final class PhabricatorFileDeleteController extends PhabricatorFileController {
5 public function handleRequest(AphrontRequest $request) {
6 $viewer = $request->getViewer();
7 $id = $request->getURIData('id');
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,
18 ->executeOne();
19 if (!$file) {
20 return new Aphront404Response();
23 if (($viewer->getPHID() != $file->getAuthorPHID()) &&
24 (!$viewer->getIsAdmin())) {
25 return new Aphront403Response();
28 if ($request->isFormPost()) {
29 $xactions = array();
31 $xactions[] = id(new PhabricatorFileTransaction())
32 ->setTransactionType(PhabricatorFileDeleteTransaction::TRANSACTIONTYPE)
33 ->setNewValue(true);
35 id(new PhabricatorFileEditor())
36 ->setActor($viewer)
37 ->setContentSourceFromRequest($request)
38 ->setContinueOnNoEffect(true)
39 ->setContinueOnMissingFields(true)
40 ->applyTransactions($file, $xactions);
42 return id(new AphrontRedirectResponse())->setURI('/file/');
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());