1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 08:42:41 +01:00

Switch File deletion to use ModularTransactions

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
This commit is contained in:
Austin McKinley 2017-04-18 12:48:59 -07:00
parent ab2aa74d6e
commit ece9579d25
4 changed files with 61 additions and 7 deletions

View file

@ -2764,6 +2764,7 @@ phutil_register_library_map(array(
'PhabricatorFileDAO' => 'applications/files/storage/PhabricatorFileDAO.php', 'PhabricatorFileDAO' => 'applications/files/storage/PhabricatorFileDAO.php',
'PhabricatorFileDataController' => 'applications/files/controller/PhabricatorFileDataController.php', 'PhabricatorFileDataController' => 'applications/files/controller/PhabricatorFileDataController.php',
'PhabricatorFileDeleteController' => 'applications/files/controller/PhabricatorFileDeleteController.php', 'PhabricatorFileDeleteController' => 'applications/files/controller/PhabricatorFileDeleteController.php',
'PhabricatorFileDeleteTransaction' => 'applications/files/xaction/PhabricatorFileDeleteTransaction.php',
'PhabricatorFileDropUploadController' => 'applications/files/controller/PhabricatorFileDropUploadController.php', 'PhabricatorFileDropUploadController' => 'applications/files/controller/PhabricatorFileDropUploadController.php',
'PhabricatorFileEditController' => 'applications/files/controller/PhabricatorFileEditController.php', 'PhabricatorFileEditController' => 'applications/files/controller/PhabricatorFileEditController.php',
'PhabricatorFileEditEngine' => 'applications/files/editor/PhabricatorFileEditEngine.php', 'PhabricatorFileEditEngine' => 'applications/files/editor/PhabricatorFileEditEngine.php',
@ -7931,6 +7932,7 @@ phutil_register_library_map(array(
'PhabricatorFileDAO' => 'PhabricatorLiskDAO', 'PhabricatorFileDAO' => 'PhabricatorLiskDAO',
'PhabricatorFileDataController' => 'PhabricatorFileController', 'PhabricatorFileDataController' => 'PhabricatorFileController',
'PhabricatorFileDeleteController' => 'PhabricatorFileController', 'PhabricatorFileDeleteController' => 'PhabricatorFileController',
'PhabricatorFileDeleteTransaction' => 'PhabricatorFileTransactionType',
'PhabricatorFileDropUploadController' => 'PhabricatorFileController', 'PhabricatorFileDropUploadController' => 'PhabricatorFileController',
'PhabricatorFileEditController' => 'PhabricatorFileController', 'PhabricatorFileEditController' => 'PhabricatorFileController',
'PhabricatorFileEditEngine' => 'PhabricatorEditEngine', 'PhabricatorFileEditEngine' => 'PhabricatorEditEngine',

View file

@ -26,14 +26,18 @@ final class PhabricatorFileDeleteController extends PhabricatorFileController {
} }
if ($request->isFormPost()) { if ($request->isFormPost()) {
// Mark the file for deletion, save it, and schedule a worker to $xactions = array();
// sweep by later and pick it up.
$file->setIsDeleted(true)->save();
PhabricatorWorker::scheduleTask( $xactions[] = id(new PhabricatorFileTransaction())
'FileDeletionWorker', ->setTransactionType(PhabricatorFileDeleteTransaction::TRANSACTIONTYPE)
array('objectPHID' => $file->getPHID()), ->setNewValue(true);
array('priority' => PhabricatorWorker::PRIORITY_BULK));
id(new PhabricatorFileEditor())
->setActor($viewer)
->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true)
->setContinueOnMissingFields(true)
->applyTransactions($file, $xactions);
return id(new AphrontRedirectResponse())->setURI('/file/'); return id(new AphrontRedirectResponse())->setURI('/file/');
} }

View file

@ -41,6 +41,9 @@ final class PhabricatorFile extends PhabricatorFileDAO
const METADATA_STORAGE = 'storage'; const METADATA_STORAGE = 'storage';
const METADATA_INTEGRITY = 'integrity'; const METADATA_INTEGRITY = 'integrity';
const STATUS_ACTIVE = 'active';
const STATUS_DELETED = 'deleted';
protected $name; protected $name;
protected $mimeType; protected $mimeType;
protected $byteSize; protected $byteSize;

View file

@ -0,0 +1,45 @@
<?php
final class PhabricatorFileDeleteTransaction
extends PhabricatorFileTransactionType {
const TRANSACTIONTYPE = 'file:delete';
public function generateOldValue($object) {
return PhabricatorFile::STATUS_ACTIVE;
}
public function applyInternalEffects($object, $value) {
$file = $object;
// Mark the file for deletion, save it, and schedule a worker to
// sweep by later and pick it up.
$file->setIsDeleted(true);
PhabricatorWorker::scheduleTask(
'FileDeletionWorker',
array('objectPHID' => $file->getPHID()),
array('priority' => PhabricatorWorker::PRIORITY_BULK));
}
public function getIcon() {
return 'fa-ban';
}
public function getColor() {
return 'red';
}
public function getTitle() {
return pht(
'%s deleted this file.',
$this->renderAuthor());
}
public function getTitleForFeed() {
return pht(
'%s deleted %s.',
$this->renderAuthor(),
$this->renderObject());
}
}