From e6ee5ee9a10488f89aa6b17d080a832e332f1c9c Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 4 Sep 2018 12:44:11 -0700 Subject: [PATCH] When applying repository operations via Drydock, provide more context on OperationType Summary: Ref T13195. See PHI845. For custom OperationTypes, provide access to the Interface and Operation via getters. This is just for convenience, since passing these around everywhere can be a bit of a pain if you have a deep-ish stack of things or love using callbacks or whatever. Test Plan: Landed a revision via upstream Drydock operations. Reviewers: amckinley Reviewed By: amckinley Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam Maniphest Tasks: T13195 Differential Revision: https://secure.phabricator.com/D19636 --- .../DrydockRepositoryOperationType.php | 23 +++++++++++++++++++ .../query/DrydockRepositoryOperationQuery.php | 7 +++++- .../storage/DrydockRepositoryOperation.php | 6 ++--- ...DrydockRepositoryOperationUpdateWorker.php | 5 ---- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/applications/drydock/operation/DrydockRepositoryOperationType.php b/src/applications/drydock/operation/DrydockRepositoryOperationType.php index 7ec3689aff..32b562a303 100644 --- a/src/applications/drydock/operation/DrydockRepositoryOperationType.php +++ b/src/applications/drydock/operation/DrydockRepositoryOperationType.php @@ -3,6 +3,8 @@ abstract class DrydockRepositoryOperationType extends Phobject { private $viewer; + private $operation; + private $interface; abstract public function applyOperation( DrydockRepositoryOperation $operation, @@ -29,6 +31,27 @@ abstract class DrydockRepositoryOperationType extends Phobject { return $this->viewer; } + final public function setOperation(DrydockRepositoryOperation $operation) { + $this->operation = $operation; + return $this; + } + + final public function getOperation() { + return $this->operation; + } + + final public function setInterface(DrydockInterface $interface) { + $this->interface = $interface; + return $this; + } + + final public function getInterface() { + if (!$this->interface) { + throw new PhutilInvalidStateException('setInterface'); + } + return $this->interface; + } + final public function getOperationConstant() { return $this->getPhobjectClassConstant('OPCONST', 32); } diff --git a/src/applications/drydock/query/DrydockRepositoryOperationQuery.php b/src/applications/drydock/query/DrydockRepositoryOperationQuery.php index fb1f6583a8..a5fbe0acc9 100644 --- a/src/applications/drydock/query/DrydockRepositoryOperationQuery.php +++ b/src/applications/drydock/query/DrydockRepositoryOperationQuery.php @@ -62,6 +62,8 @@ final class DrydockRepositoryOperationQuery extends DrydockQuery { protected function willFilterPage(array $operations) { $implementations = DrydockRepositoryOperationType::getAllOperationTypes(); + $viewer = $this->getViewer(); + foreach ($operations as $key => $operation) { $impl = idx($implementations, $operation->getOperationType()); if (!$impl) { @@ -69,7 +71,10 @@ final class DrydockRepositoryOperationQuery extends DrydockQuery { unset($operations[$key]); continue; } - $impl = clone $impl; + $impl = id(clone $impl) + ->setViewer($viewer) + ->setOperation($operation); + $operation->attachImplementation($impl); } diff --git a/src/applications/drydock/storage/DrydockRepositoryOperation.php b/src/applications/drydock/storage/DrydockRepositoryOperation.php index 4e25280c3f..809a10a116 100644 --- a/src/applications/drydock/storage/DrydockRepositoryOperation.php +++ b/src/applications/drydock/storage/DrydockRepositoryOperation.php @@ -137,9 +137,9 @@ final class DrydockRepositoryOperation extends DrydockDAO } public function applyOperation(DrydockInterface $interface) { - return $this->getImplementation()->applyOperation( - $this, - $interface); + $impl = $this->getImplementation(); + $impl->setInterface($interface); + return $impl->applyOperation($this, $interface); } public function getOperationDescription(PhabricatorUser $viewer) { diff --git a/src/applications/drydock/worker/DrydockRepositoryOperationUpdateWorker.php b/src/applications/drydock/worker/DrydockRepositoryOperationUpdateWorker.php index dfd603fd12..2ee9324fb6 100644 --- a/src/applications/drydock/worker/DrydockRepositoryOperationUpdateWorker.php +++ b/src/applications/drydock/worker/DrydockRepositoryOperationUpdateWorker.php @@ -25,8 +25,6 @@ final class DrydockRepositoryOperationUpdateWorker private function handleUpdate(DrydockRepositoryOperation $operation) { - $viewer = $this->getViewer(); - $operation_state = $operation->getOperationState(); switch ($operation_state) { @@ -53,9 +51,6 @@ final class DrydockRepositoryOperationUpdateWorker // waiting for a lease we're holding. try { - $operation->getImplementation() - ->setViewer($viewer); - $lease = $this->loadWorkingCopyLease($operation); $interface = $lease->getInterface(