1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-19 03:01:11 +01:00

Reduce PhabricatorUser::getOmnipotentUser calls by adding a getViewer method to PhbaricatorDestructionEngine

Summary:
Fixes T6956. Before this change, we called PhabricatorUser::getOmnipotentUser in the various delete methods to query the data. Now, we use $engine->getViewer(), since its always a good thing to have less calls to PhabricatorUser::getOmnipotentUser thrown around the codebase.

I used the "codemod" tool to audit the existing calls to PhabricatorDestructorEngine (all of them) so ostensibly this gets all the spots. If I missed something though, its still going to work, so this change is very low risk.

Test Plan: ./bin/remove destroy P1; visit P1 and get a 404

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T6956

Differential Revision: https://secure.phabricator.com/D12866
This commit is contained in:
Bob Trahan 2015-05-15 14:07:17 -07:00
parent b6733e4a86
commit 3ef0721ada
10 changed files with 14 additions and 10 deletions

View file

@ -240,7 +240,7 @@ final class AlmanacDevice
PhabricatorDestructionEngine $engine) {
$interfaces = id(new AlmanacInterfaceQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->setViewer($engine->getViewer())
->withDevicePHIDs(array($this->getPHID()))
->execute();
foreach ($interfaces as $interface) {

View file

@ -119,7 +119,7 @@ final class AlmanacInterface
PhabricatorDestructionEngine $engine) {
$bindings = id(new AlmanacBindingQuery())
->setViewer($this->getViewer())
->setViewer($engine->getViewer())
->withInterfacePHIDs(array($this->getPHID()))
->execute();
foreach ($bindings as $binding) {

View file

@ -103,7 +103,7 @@ final class AlmanacNetwork
PhabricatorDestructionEngine $engine) {
$interfaces = id(new AlmanacInterfaceQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->setViewer($engine->getViewer())
->withNetworkPHIDs(array($this->getPHID()))
->execute();

View file

@ -221,7 +221,7 @@ final class AlmanacService
PhabricatorDestructionEngine $engine) {
$bindings = id(new AlmanacBindingQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->setViewer($engine->getViewer())
->withServicePHIDs(array($this->getPHID()))
->execute();
foreach ($bindings as $binding) {

View file

@ -550,7 +550,7 @@ final class DifferentialRevision extends DifferentialDAO
$this->openTransaction();
$diffs = id(new DifferentialDiffQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->setViewer($engine->getViewer())
->withRevisionIDs(array($this->getID()))
->execute();
foreach ($diffs as $diff) {

View file

@ -91,7 +91,7 @@ final class DivinerLiveBook extends DivinerDAO
$this->openTransaction();
$atoms = id(new DivinerAtomQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->setViewer($engine->getViewer())
->withBookPHIDs(array($this->getPHID()))
->withIncludeGhosts(true)
->withIncludeUndocumentable(true)

View file

@ -104,8 +104,9 @@ final class PhabricatorFileTransformController
}
private function destroyTransform(PhabricatorTransformedFile $xform) {
$engine = new PhabricatorDestructionEngine();
$file = id(new PhabricatorFileQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->setViewer($engine->getViewer())
->withPHIDs(array($xform->getTransformedPHID()))
->executeOne();
@ -114,7 +115,6 @@ final class PhabricatorFileTransformController
if (!$file) {
$xform->delete();
} else {
$engine = new PhabricatorDestructionEngine();
$engine->destroyObject($file);
}

View file

@ -91,7 +91,7 @@ final class PhabricatorFileChunk extends PhabricatorFileDAO
$data_phid = $this->getDataFilePHID();
if ($data_phid) {
$data_file = id(new PhabricatorFileQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->setViewer($engine->getViewer())
->withPHIDs(array($data_phid))
->executeOne();
if ($data_file) {

View file

@ -172,7 +172,7 @@ final class PhabricatorPaste extends PhabricatorPasteDAO
if ($this->filePHID) {
$file = id(new PhabricatorFileQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->setViewer($engine->getViewer())
->withPHIDs(array($this->filePHID))
->executeOne();
if ($file) {

View file

@ -4,6 +4,10 @@ final class PhabricatorDestructionEngine extends Phobject {
private $rootLogID;
public function getViewer() {
return PhabricatorUser::getOmnipotentUser();
}
public function destroyObject(PhabricatorDestructibleInterface $object) {
$log = id(new PhabricatorSystemDestructionLog())
->setEpoch(time())