1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-19 20:10:55 +01:00

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
This commit is contained in:
epriestley 2014-04-17 16:03:24 -07:00
parent 62973e0f53
commit 49bc32f12d
9 changed files with 99 additions and 6 deletions

View file

@ -2951,6 +2951,7 @@ phutil_register_library_map(array(
0 => 'DifferentialDAO',
1 => 'PhabricatorPolicyInterface',
2 => 'HarbormasterBuildableInterface',
3 => 'PhabricatorApplicationTransactionInterface',
),
'DifferentialDiffCreateController' => 'DifferentialController',
'DifferentialDiffProperty' => 'DifferentialDAO',
@ -3015,6 +3016,7 @@ phutil_register_library_map(array(
5 => 'HarbormasterBuildableInterface',
6 => 'PhabricatorSubscribableInterface',
7 => 'PhabricatorCustomFieldInterface',
8 => 'PhabricatorApplicationTransactionInterface',
),
'DifferentialRevisionDetailView' => 'AphrontView',
'DifferentialRevisionEditController' => 'DifferentialController',

View file

@ -4,7 +4,8 @@ final class DifferentialDiff
extends DifferentialDAO
implements
PhabricatorPolicyInterface,
HarbormasterBuildableInterface {
HarbormasterBuildableInterface,
PhabricatorApplicationTransactionInterface {
protected $revisionID;
protected $authorPHID;
@ -349,4 +350,30 @@ final class DifferentialDiff
return null;
}
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
public function getApplicationTransactionEditor() {
if (!$this->getRevisionID()) {
return null;
}
return $this->getRevision()->getApplicationTransactionEditor();
}
public function getApplicationTransactionObject() {
if (!$this->getRevisionID()) {
return null;
}
return $this->getRevision();
}
public function getApplicationTransactionTemplate() {
if (!$this->getRevisionID()) {
return null;
}
return $this->getRevision()->getApplicationTransactionTemplate();
}
}

View file

@ -8,7 +8,8 @@ final class DifferentialRevision extends DifferentialDAO
PhrequentTrackableInterface,
HarbormasterBuildableInterface,
PhabricatorSubscribableInterface,
PhabricatorCustomFieldInterface {
PhabricatorCustomFieldInterface,
PhabricatorApplicationTransactionInterface {
protected $title = '';
protected $originalTitle;
@ -460,4 +461,20 @@ final class DifferentialRevision extends DifferentialDAO
return $this;
}
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
public function getApplicationTransactionEditor() {
return new DifferentialTransactionEditor();
}
public function getApplicationTransactionObject() {
return $this;
}
public function getApplicationTransactionTemplate() {
return new DifferentialTransaction();
}
}

View file

@ -145,11 +145,16 @@ final class LegalpadDocument extends LegalpadDAO
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
public function getApplicationTransactionEditor() {
return new LegalpadDocumentEditor();
}
public function getApplicationTransactionObject() {
return $this;
}
public function getApplicationTransactionTemplate() {
return new LegalpadTransaction();
}

View file

@ -68,6 +68,10 @@ final class PhabricatorFileImageMacro extends PhabricatorFileDAO
}
public function getApplicationTransactionObject() {
return $this;
}
public function getApplicationTransactionTemplate() {
return new PhabricatorMacroTransaction();
}

View file

@ -219,6 +219,10 @@ final class PholioMock extends PholioDAO
}
public function getApplicationTransactionObject() {
return $this;
}
public function getApplicationTransactionTemplate() {
return new PholioTransaction();
}

View file

@ -70,13 +70,15 @@ final class PhabricatorSearchAttachController
$txn_editor = $object->getApplicationTransactionEditor()
->setActor($user)
->setContentSourceFromRequest($request);
$txn_template = $object->getApplicationTransactionObject()
$txn_template = $object->getApplicationTransactionTemplate()
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
->setMetadataValue('edge:type', $edge_type)
->setNewValue(array(
'+' => array_fuse($add_phids),
'-' => array_fuse($rem_phids)));
$txn_editor->applyTransactions($object, array($txn_template));
$txn_editor->applyTransactions(
$object->getApplicationTransactionObject(),
array($txn_template));
} else {

View file

@ -74,7 +74,7 @@ final class PhabricatorSubscriptionsEditController
);
}
$xaction = id($object->getApplicationTransactionObject())
$xaction = id($object->getApplicationTransactionTemplate())
->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS)
->setNewValue($xaction_value);
@ -83,7 +83,9 @@ final class PhabricatorSubscriptionsEditController
->setContinueOnNoEffect(true)
->setContentSourceFromRequest($request);
$editor->applyTransactions($object, array($xaction));
$editor->applyTransactions(
$object->getApplicationTransactionObject(),
array($xaction));
} else {
// TODO: Eventually, get rid of this once everything implements

View file

@ -1,8 +1,38 @@
<?php
/**
* Allow infrastructure to apply transactions to the implementing object.
*
* For example, implementing this interface allows Subscriptions to apply CC
* transactions, and allows Harbormaster to apply build result notifications.
*/
interface PhabricatorApplicationTransactionInterface {
/**
* Return a @{class:PhabricatorApplicationTransactionEditor} which can be
* used to apply transactions to this object.
*
* @return PhabricatorApplicationTransactionEditor Editor for this object.
*/
public function getApplicationTransactionEditor();
/**
* Return the object to apply transactions to. Normally this is the current
* object (that is, `$this`), but in some cases transactions may apply to
* a different object: for example, @{class:DifferentialDiff} applies
* transactions to the associated @{class:DifferentialRevision}.
*
* @return PhabricatorLiskDAO Object to apply transactions to.
*/
public function getApplicationTransactionObject();
/**
* Return a template transaction for this object.
*
* @return PhabricatorApplicationTransaction
*/
public function getApplicationTransactionTemplate();
}