Skip to content

Commit e6ee5ee

Browse files
author
epriestley
committed
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
1 parent 0413929 commit e6ee5ee

File tree

4 files changed

+32
-9
lines changed

4 files changed

+32
-9
lines changed

src/applications/drydock/operation/DrydockRepositoryOperationType.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
abstract class DrydockRepositoryOperationType extends Phobject {
44

55
private $viewer;
6+
private $operation;
7+
private $interface;
68

79
abstract public function applyOperation(
810
DrydockRepositoryOperation $operation,
@@ -29,6 +31,27 @@ final public function getViewer() {
2931
return $this->viewer;
3032
}
3133

34+
final public function setOperation(DrydockRepositoryOperation $operation) {
35+
$this->operation = $operation;
36+
return $this;
37+
}
38+
39+
final public function getOperation() {
40+
return $this->operation;
41+
}
42+
43+
final public function setInterface(DrydockInterface $interface) {
44+
$this->interface = $interface;
45+
return $this;
46+
}
47+
48+
final public function getInterface() {
49+
if (!$this->interface) {
50+
throw new PhutilInvalidStateException('setInterface');
51+
}
52+
return $this->interface;
53+
}
54+
3255
final public function getOperationConstant() {
3356
return $this->getPhobjectClassConstant('OPCONST', 32);
3457
}

src/applications/drydock/query/DrydockRepositoryOperationQuery.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,19 @@ protected function loadPage() {
6262
protected function willFilterPage(array $operations) {
6363
$implementations = DrydockRepositoryOperationType::getAllOperationTypes();
6464

65+
$viewer = $this->getViewer();
66+
6567
foreach ($operations as $key => $operation) {
6668
$impl = idx($implementations, $operation->getOperationType());
6769
if (!$impl) {
6870
$this->didRejectResult($operation);
6971
unset($operations[$key]);
7072
continue;
7173
}
72-
$impl = clone $impl;
74+
$impl = id(clone $impl)
75+
->setViewer($viewer)
76+
->setOperation($operation);
77+
7378
$operation->attachImplementation($impl);
7479
}
7580

src/applications/drydock/storage/DrydockRepositoryOperation.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ public function scheduleUpdate() {
137137
}
138138

139139
public function applyOperation(DrydockInterface $interface) {
140-
return $this->getImplementation()->applyOperation(
141-
$this,
142-
$interface);
140+
$impl = $this->getImplementation();
141+
$impl->setInterface($interface);
142+
return $impl->applyOperation($this, $interface);
143143
}
144144

145145
public function getOperationDescription(PhabricatorUser $viewer) {

src/applications/drydock/worker/DrydockRepositoryOperationUpdateWorker.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ protected function doWork() {
2525

2626

2727
private function handleUpdate(DrydockRepositoryOperation $operation) {
28-
$viewer = $this->getViewer();
29-
3028
$operation_state = $operation->getOperationState();
3129

3230
switch ($operation_state) {
@@ -53,9 +51,6 @@ private function handleUpdate(DrydockRepositoryOperation $operation) {
5351
// waiting for a lease we're holding.
5452

5553
try {
56-
$operation->getImplementation()
57-
->setViewer($viewer);
58-
5954
$lease = $this->loadWorkingCopyLease($operation);
6055

6156
$interface = $lease->getInterface(

0 commit comments

Comments
 (0)