Skip to content

Commit 49bc32f

Browse files
author
epriestley
committed
Implement PhabricatorApplicationTransactionInterface in Differential
Summary: Ref T4810. Ultimate goal is to let Harbormaster post a "build passed/failed" transaction. To prepare for that, implement `PhabricatorApplicationTransactionInterface` in Differential. To allow Harbormaster to take action on //diffs// but have the transactions apply to //revisions//, I added a new method so that objects can redirect transactions to some other object. Test Plan: - Subscribed/unsubscribed/attached/detached from Differential, saw transactions appear properly. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T4810 Differential Revision: https://secure.phabricator.com/D8802
1 parent 62973e0 commit 49bc32f

File tree

9 files changed

+99
-6
lines changed

9 files changed

+99
-6
lines changed

src/__phutil_library_map__.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2951,6 +2951,7 @@
29512951
0 => 'DifferentialDAO',
29522952
1 => 'PhabricatorPolicyInterface',
29532953
2 => 'HarbormasterBuildableInterface',
2954+
3 => 'PhabricatorApplicationTransactionInterface',
29542955
),
29552956
'DifferentialDiffCreateController' => 'DifferentialController',
29562957
'DifferentialDiffProperty' => 'DifferentialDAO',
@@ -3015,6 +3016,7 @@
30153016
5 => 'HarbormasterBuildableInterface',
30163017
6 => 'PhabricatorSubscribableInterface',
30173018
7 => 'PhabricatorCustomFieldInterface',
3019+
8 => 'PhabricatorApplicationTransactionInterface',
30183020
),
30193021
'DifferentialRevisionDetailView' => 'AphrontView',
30203022
'DifferentialRevisionEditController' => 'DifferentialController',

src/applications/differential/storage/DifferentialDiff.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ final class DifferentialDiff
44
extends DifferentialDAO
55
implements
66
PhabricatorPolicyInterface,
7-
HarbormasterBuildableInterface {
7+
HarbormasterBuildableInterface,
8+
PhabricatorApplicationTransactionInterface {
89

910
protected $revisionID;
1011
protected $authorPHID;
@@ -349,4 +350,30 @@ public function getHarbormasterContainerPHID() {
349350
return null;
350351
}
351352

353+
354+
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
355+
356+
357+
public function getApplicationTransactionEditor() {
358+
if (!$this->getRevisionID()) {
359+
return null;
360+
}
361+
return $this->getRevision()->getApplicationTransactionEditor();
362+
}
363+
364+
365+
public function getApplicationTransactionObject() {
366+
if (!$this->getRevisionID()) {
367+
return null;
368+
}
369+
return $this->getRevision();
370+
}
371+
372+
public function getApplicationTransactionTemplate() {
373+
if (!$this->getRevisionID()) {
374+
return null;
375+
}
376+
return $this->getRevision()->getApplicationTransactionTemplate();
377+
}
378+
352379
}

src/applications/differential/storage/DifferentialRevision.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ final class DifferentialRevision extends DifferentialDAO
88
PhrequentTrackableInterface,
99
HarbormasterBuildableInterface,
1010
PhabricatorSubscribableInterface,
11-
PhabricatorCustomFieldInterface {
11+
PhabricatorCustomFieldInterface,
12+
PhabricatorApplicationTransactionInterface {
1213

1314
protected $title = '';
1415
protected $originalTitle;
@@ -460,4 +461,20 @@ public function attachCustomFields(PhabricatorCustomFieldAttachment $fields) {
460461
return $this;
461462
}
462463

464+
465+
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
466+
467+
468+
public function getApplicationTransactionEditor() {
469+
return new DifferentialTransactionEditor();
470+
}
471+
472+
public function getApplicationTransactionObject() {
473+
return $this;
474+
}
475+
476+
public function getApplicationTransactionTemplate() {
477+
return new DifferentialTransaction();
478+
}
479+
463480
}

src/applications/legalpad/storage/LegalpadDocument.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,16 @@ public function describeAutomaticCapability($capability) {
145145

146146
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
147147

148+
148149
public function getApplicationTransactionEditor() {
149150
return new LegalpadDocumentEditor();
150151
}
151152

152153
public function getApplicationTransactionObject() {
154+
return $this;
155+
}
156+
157+
public function getApplicationTransactionTemplate() {
153158
return new LegalpadTransaction();
154159
}
155160

src/applications/macro/storage/PhabricatorFileImageMacro.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ public function getApplicationTransactionEditor() {
6868
}
6969

7070
public function getApplicationTransactionObject() {
71+
return $this;
72+
}
73+
74+
public function getApplicationTransactionTemplate() {
7175
return new PhabricatorMacroTransaction();
7276
}
7377

src/applications/pholio/storage/PholioMock.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ public function getApplicationTransactionEditor() {
219219
}
220220

221221
public function getApplicationTransactionObject() {
222+
return $this;
223+
}
224+
225+
public function getApplicationTransactionTemplate() {
222226
return new PholioTransaction();
223227
}
224228

src/applications/search/controller/PhabricatorSearchAttachController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,15 @@ public function processRequest() {
7070
$txn_editor = $object->getApplicationTransactionEditor()
7171
->setActor($user)
7272
->setContentSourceFromRequest($request);
73-
$txn_template = $object->getApplicationTransactionObject()
73+
$txn_template = $object->getApplicationTransactionTemplate()
7474
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
7575
->setMetadataValue('edge:type', $edge_type)
7676
->setNewValue(array(
7777
'+' => array_fuse($add_phids),
7878
'-' => array_fuse($rem_phids)));
79-
$txn_editor->applyTransactions($object, array($txn_template));
79+
$txn_editor->applyTransactions(
80+
$object->getApplicationTransactionObject(),
81+
array($txn_template));
8082

8183
} else {
8284

src/applications/subscriptions/controller/PhabricatorSubscriptionsEditController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function processRequest() {
7474
);
7575
}
7676

77-
$xaction = id($object->getApplicationTransactionObject())
77+
$xaction = id($object->getApplicationTransactionTemplate())
7878
->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS)
7979
->setNewValue($xaction_value);
8080

@@ -83,7 +83,9 @@ public function processRequest() {
8383
->setContinueOnNoEffect(true)
8484
->setContentSourceFromRequest($request);
8585

86-
$editor->applyTransactions($object, array($xaction));
86+
$editor->applyTransactions(
87+
$object->getApplicationTransactionObject(),
88+
array($xaction));
8789
} else {
8890

8991
// TODO: Eventually, get rid of this once everything implements
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,38 @@
11
<?php
22

3+
/**
4+
* Allow infrastructure to apply transactions to the implementing object.
5+
*
6+
* For example, implementing this interface allows Subscriptions to apply CC
7+
* transactions, and allows Harbormaster to apply build result notifications.
8+
*/
39
interface PhabricatorApplicationTransactionInterface {
410

11+
/**
12+
* Return a @{class:PhabricatorApplicationTransactionEditor} which can be
13+
* used to apply transactions to this object.
14+
*
15+
* @return PhabricatorApplicationTransactionEditor Editor for this object.
16+
*/
517
public function getApplicationTransactionEditor();
18+
19+
20+
/**
21+
* Return the object to apply transactions to. Normally this is the current
22+
* object (that is, `$this`), but in some cases transactions may apply to
23+
* a different object: for example, @{class:DifferentialDiff} applies
24+
* transactions to the associated @{class:DifferentialRevision}.
25+
*
26+
* @return PhabricatorLiskDAO Object to apply transactions to.
27+
*/
628
public function getApplicationTransactionObject();
729

30+
31+
/**
32+
* Return a template transaction for this object.
33+
*
34+
* @return PhabricatorApplicationTransaction
35+
*/
36+
public function getApplicationTransactionTemplate();
37+
838
}

0 commit comments

Comments
 (0)