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

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
This commit is contained in:
epriestley 2018-09-04 12:44:11 -07:00
parent 041392988e
commit e6ee5ee9a1
4 changed files with 32 additions and 9 deletions

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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) {

View file

@ -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(