From 49bc32f12d82e7e5ca324aa02d18bf550841ed83 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 17 Apr 2014 16:03:24 -0700 Subject: [PATCH] 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 --- src/__phutil_library_map__.php | 2 ++ .../differential/storage/DifferentialDiff.php | 29 +++++++++++++++++- .../storage/DifferentialRevision.php | 19 +++++++++++- .../legalpad/storage/LegalpadDocument.php | 5 ++++ .../storage/PhabricatorFileImageMacro.php | 4 +++ .../pholio/storage/PholioMock.php | 4 +++ .../PhabricatorSearchAttachController.php | 6 ++-- ...PhabricatorSubscriptionsEditController.php | 6 ++-- ...ricatorApplicationTransactionInterface.php | 30 +++++++++++++++++++ 9 files changed, 99 insertions(+), 6 deletions(-) diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 977781c57e..24133994ca 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -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', diff --git a/src/applications/differential/storage/DifferentialDiff.php b/src/applications/differential/storage/DifferentialDiff.php index 6af2bb9f6f..88398e856a 100644 --- a/src/applications/differential/storage/DifferentialDiff.php +++ b/src/applications/differential/storage/DifferentialDiff.php @@ -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(); + } + } diff --git a/src/applications/differential/storage/DifferentialRevision.php b/src/applications/differential/storage/DifferentialRevision.php index 12e659ecda..398ffa985b 100644 --- a/src/applications/differential/storage/DifferentialRevision.php +++ b/src/applications/differential/storage/DifferentialRevision.php @@ -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(); + } + } diff --git a/src/applications/legalpad/storage/LegalpadDocument.php b/src/applications/legalpad/storage/LegalpadDocument.php index 6a3e4d18f9..7218639c23 100644 --- a/src/applications/legalpad/storage/LegalpadDocument.php +++ b/src/applications/legalpad/storage/LegalpadDocument.php @@ -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(); } diff --git a/src/applications/macro/storage/PhabricatorFileImageMacro.php b/src/applications/macro/storage/PhabricatorFileImageMacro.php index 578e0c3513..0318c025b6 100644 --- a/src/applications/macro/storage/PhabricatorFileImageMacro.php +++ b/src/applications/macro/storage/PhabricatorFileImageMacro.php @@ -68,6 +68,10 @@ final class PhabricatorFileImageMacro extends PhabricatorFileDAO } public function getApplicationTransactionObject() { + return $this; + } + + public function getApplicationTransactionTemplate() { return new PhabricatorMacroTransaction(); } diff --git a/src/applications/pholio/storage/PholioMock.php b/src/applications/pholio/storage/PholioMock.php index 3f48f31501..0504dd6dff 100644 --- a/src/applications/pholio/storage/PholioMock.php +++ b/src/applications/pholio/storage/PholioMock.php @@ -219,6 +219,10 @@ final class PholioMock extends PholioDAO } public function getApplicationTransactionObject() { + return $this; + } + + public function getApplicationTransactionTemplate() { return new PholioTransaction(); } diff --git a/src/applications/search/controller/PhabricatorSearchAttachController.php b/src/applications/search/controller/PhabricatorSearchAttachController.php index 2155d41db5..42bc95a8cc 100644 --- a/src/applications/search/controller/PhabricatorSearchAttachController.php +++ b/src/applications/search/controller/PhabricatorSearchAttachController.php @@ -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 { diff --git a/src/applications/subscriptions/controller/PhabricatorSubscriptionsEditController.php b/src/applications/subscriptions/controller/PhabricatorSubscriptionsEditController.php index 5dfd9b01f0..c65a4b1a39 100644 --- a/src/applications/subscriptions/controller/PhabricatorSubscriptionsEditController.php +++ b/src/applications/subscriptions/controller/PhabricatorSubscriptionsEditController.php @@ -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 diff --git a/src/applications/transactions/interface/PhabricatorApplicationTransactionInterface.php b/src/applications/transactions/interface/PhabricatorApplicationTransactionInterface.php index be9b01d95b..eac4cf30dd 100644 --- a/src/applications/transactions/interface/PhabricatorApplicationTransactionInterface.php +++ b/src/applications/transactions/interface/PhabricatorApplicationTransactionInterface.php @@ -1,8 +1,38 @@