mirror of
https://we.phorge.it/source/phorge.git
synced 2025-03-03 16:09:17 +01:00
Summary: Fixes T12587. Adds a new `PhabricatorFileDeleteTransaction` that enqueues `File` delete tasks. Test Plan: - hack `PhabricatorFileQuery` to ignore isDeleted state - stop daemons - upload a file, delete it from the UI - check that the DB has updated isDeleted = 1 - check timeline rendering in `File` detail view - start daemons - confirm rows are deleted from DB Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin, thoughtpolice Maniphest Tasks: T12587 Differential Revision: https://secure.phabricator.com/D17723
55 lines
1.6 KiB
PHP
55 lines
1.6 KiB
PHP
<?php
|
|
|
|
final class PhabricatorFileDeleteController extends PhabricatorFileController {
|
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
$viewer = $request->getViewer();
|
|
$id = $request->getURIData('id');
|
|
|
|
$file = id(new PhabricatorFileQuery())
|
|
->setViewer($viewer)
|
|
->withIDs(array($id))
|
|
->withIsDeleted(false)
|
|
->requireCapabilities(
|
|
array(
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
))
|
|
->executeOne();
|
|
if (!$file) {
|
|
return new Aphront404Response();
|
|
}
|
|
|
|
if (($viewer->getPHID() != $file->getAuthorPHID()) &&
|
|
(!$viewer->getIsAdmin())) {
|
|
return new Aphront403Response();
|
|
}
|
|
|
|
if ($request->isFormPost()) {
|
|
$xactions = array();
|
|
|
|
$xactions[] = id(new PhabricatorFileTransaction())
|
|
->setTransactionType(PhabricatorFileDeleteTransaction::TRANSACTIONTYPE)
|
|
->setNewValue(true);
|
|
|
|
id(new PhabricatorFileEditor())
|
|
->setActor($viewer)
|
|
->setContentSourceFromRequest($request)
|
|
->setContinueOnNoEffect(true)
|
|
->setContinueOnMissingFields(true)
|
|
->applyTransactions($file, $xactions);
|
|
|
|
return id(new AphrontRedirectResponse())->setURI('/file/');
|
|
}
|
|
|
|
return $this->newDialog()
|
|
->setTitle(pht('Really delete file?'))
|
|
->appendChild(hsprintf(
|
|
'<p>%s</p>',
|
|
pht(
|
|
'Permanently delete "%s"? This action can not be undone.',
|
|
$file->getName())))
|
|
->addSubmitButton(pht('Delete'))
|
|
->addCancelButton($file->getInfoURI());
|
|
}
|
|
}
|