Changeset View
Changeset View
Standalone View
Standalone View
src/applications/files/worker/FileDeletionWorker.php
- This file was added.
<?php | |||||
final class FileDeletionWorker extends PhabricatorWorker { | |||||
private function loadFile() { | |||||
$phid = idx($this->getTaskData(), 'objectPHID'); | |||||
epriestley: I think this cache doesn't save us anything, and it's possible we might run into trouble with… | |||||
if (!$phid) { | |||||
throw new PhabricatorWorkerPermanentFailureException( | |||||
pht('No "%s" in task data.', 'objectPHID')); | |||||
} | |||||
$file = id(new PhabricatorFileQuery()) | |||||
->setViewer(PhabricatorUser::getOmnipotentUser()) | |||||
Done Inline ActionsThis is extremely minor, but consider using filePHID instead of fileID -- the major benefit is that it's a little easier to debug stuff because PHIDs can go into more tools (like bin/remove destroy, global search, etc). epriestley: This is extremely minor, but consider using `filePHID` instead of `fileID` -- the major benefit… | |||||
->withPHIDs(array($phid)) | |||||
->executeOne(); | |||||
if (!$file) { | |||||
throw new PhabricatorWorkerPermanentFailureException( | |||||
pht('File "%s" does not exist.', $phid)); | |||||
} | |||||
return $file; | |||||
} | |||||
protected function doWork() { | |||||
$file = $this->loadFile(); | |||||
$engine = new PhabricatorDestructionEngine(); | |||||
$engine->destroyObject($file); | |||||
} | |||||
} |
I think this cache doesn't save us anything, and it's possible we might run into trouble with it if the same Worker is ever used to run multiple jobs. That is, it makes this code not work:
Pretty sure we don't do that, and wouldn't really expect it to work, but maybe get rid of the cache since the best case is nothing and the worst case is a confusing surprise for someone a couple years from now.