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:
		| @@ -2951,6 +2951,7 @@ phutil_register_library_map(array( | |||||||
|       0 => 'DifferentialDAO', |       0 => 'DifferentialDAO', | ||||||
|       1 => 'PhabricatorPolicyInterface', |       1 => 'PhabricatorPolicyInterface', | ||||||
|       2 => 'HarbormasterBuildableInterface', |       2 => 'HarbormasterBuildableInterface', | ||||||
|  |       3 => 'PhabricatorApplicationTransactionInterface', | ||||||
|     ), |     ), | ||||||
|     'DifferentialDiffCreateController' => 'DifferentialController', |     'DifferentialDiffCreateController' => 'DifferentialController', | ||||||
|     'DifferentialDiffProperty' => 'DifferentialDAO', |     'DifferentialDiffProperty' => 'DifferentialDAO', | ||||||
| @@ -3015,6 +3016,7 @@ phutil_register_library_map(array( | |||||||
|       5 => 'HarbormasterBuildableInterface', |       5 => 'HarbormasterBuildableInterface', | ||||||
|       6 => 'PhabricatorSubscribableInterface', |       6 => 'PhabricatorSubscribableInterface', | ||||||
|       7 => 'PhabricatorCustomFieldInterface', |       7 => 'PhabricatorCustomFieldInterface', | ||||||
|  |       8 => 'PhabricatorApplicationTransactionInterface', | ||||||
|     ), |     ), | ||||||
|     'DifferentialRevisionDetailView' => 'AphrontView', |     'DifferentialRevisionDetailView' => 'AphrontView', | ||||||
|     'DifferentialRevisionEditController' => 'DifferentialController', |     'DifferentialRevisionEditController' => 'DifferentialController', | ||||||
|   | |||||||
| @@ -4,7 +4,8 @@ final class DifferentialDiff | |||||||
|   extends DifferentialDAO |   extends DifferentialDAO | ||||||
|   implements |   implements | ||||||
|     PhabricatorPolicyInterface, |     PhabricatorPolicyInterface, | ||||||
|     HarbormasterBuildableInterface { |     HarbormasterBuildableInterface, | ||||||
|  |     PhabricatorApplicationTransactionInterface { | ||||||
|  |  | ||||||
|   protected $revisionID; |   protected $revisionID; | ||||||
|   protected $authorPHID; |   protected $authorPHID; | ||||||
| @@ -349,4 +350,30 @@ final class DifferentialDiff | |||||||
|     return null; |     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(); | ||||||
|  |   } | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -8,7 +8,8 @@ final class DifferentialRevision extends DifferentialDAO | |||||||
|     PhrequentTrackableInterface, |     PhrequentTrackableInterface, | ||||||
|     HarbormasterBuildableInterface, |     HarbormasterBuildableInterface, | ||||||
|     PhabricatorSubscribableInterface, |     PhabricatorSubscribableInterface, | ||||||
|     PhabricatorCustomFieldInterface { |     PhabricatorCustomFieldInterface, | ||||||
|  |     PhabricatorApplicationTransactionInterface { | ||||||
|  |  | ||||||
|   protected $title = ''; |   protected $title = ''; | ||||||
|   protected $originalTitle; |   protected $originalTitle; | ||||||
| @@ -460,4 +461,20 @@ final class DifferentialRevision extends DifferentialDAO | |||||||
|     return $this; |     return $this; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | /* -(  PhabricatorApplicationTransactionInterface  )------------------------- */ | ||||||
|  |  | ||||||
|  |  | ||||||
|  |   public function getApplicationTransactionEditor() { | ||||||
|  |     return new DifferentialTransactionEditor(); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public function getApplicationTransactionObject() { | ||||||
|  |     return $this; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public function getApplicationTransactionTemplate() { | ||||||
|  |     return new DifferentialTransaction(); | ||||||
|  |   } | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -145,11 +145,16 @@ final class LegalpadDocument extends LegalpadDAO | |||||||
|  |  | ||||||
| /* -(  PhabricatorApplicationTransactionInterface  )------------------------- */ | /* -(  PhabricatorApplicationTransactionInterface  )------------------------- */ | ||||||
|  |  | ||||||
|  |  | ||||||
|   public function getApplicationTransactionEditor() { |   public function getApplicationTransactionEditor() { | ||||||
|     return new LegalpadDocumentEditor(); |     return new LegalpadDocumentEditor(); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   public function getApplicationTransactionObject() { |   public function getApplicationTransactionObject() { | ||||||
|  |     return $this; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public function getApplicationTransactionTemplate() { | ||||||
|     return new LegalpadTransaction(); |     return new LegalpadTransaction(); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -68,6 +68,10 @@ final class PhabricatorFileImageMacro extends PhabricatorFileDAO | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   public function getApplicationTransactionObject() { |   public function getApplicationTransactionObject() { | ||||||
|  |     return $this; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public function getApplicationTransactionTemplate() { | ||||||
|     return new PhabricatorMacroTransaction(); |     return new PhabricatorMacroTransaction(); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -219,6 +219,10 @@ final class PholioMock extends PholioDAO | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   public function getApplicationTransactionObject() { |   public function getApplicationTransactionObject() { | ||||||
|  |     return $this; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public function getApplicationTransactionTemplate() { | ||||||
|     return new PholioTransaction(); |     return new PholioTransaction(); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -70,13 +70,15 @@ final class PhabricatorSearchAttachController | |||||||
|           $txn_editor = $object->getApplicationTransactionEditor() |           $txn_editor = $object->getApplicationTransactionEditor() | ||||||
|             ->setActor($user) |             ->setActor($user) | ||||||
|             ->setContentSourceFromRequest($request); |             ->setContentSourceFromRequest($request); | ||||||
|           $txn_template = $object->getApplicationTransactionObject() |           $txn_template = $object->getApplicationTransactionTemplate() | ||||||
|             ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) |             ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) | ||||||
|             ->setMetadataValue('edge:type', $edge_type) |             ->setMetadataValue('edge:type', $edge_type) | ||||||
|             ->setNewValue(array( |             ->setNewValue(array( | ||||||
|               '+' => array_fuse($add_phids), |               '+' => array_fuse($add_phids), | ||||||
|               '-' => array_fuse($rem_phids))); |               '-' => array_fuse($rem_phids))); | ||||||
|           $txn_editor->applyTransactions($object, array($txn_template)); |           $txn_editor->applyTransactions( | ||||||
|  |             $object->getApplicationTransactionObject(), | ||||||
|  |             array($txn_template)); | ||||||
|  |  | ||||||
|         } else { |         } else { | ||||||
|  |  | ||||||
|   | |||||||
| @@ -74,7 +74,7 @@ final class PhabricatorSubscriptionsEditController | |||||||
|         ); |         ); | ||||||
|       } |       } | ||||||
|  |  | ||||||
|       $xaction = id($object->getApplicationTransactionObject()) |       $xaction = id($object->getApplicationTransactionTemplate()) | ||||||
|         ->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS) |         ->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS) | ||||||
|         ->setNewValue($xaction_value); |         ->setNewValue($xaction_value); | ||||||
|  |  | ||||||
| @@ -83,7 +83,9 @@ final class PhabricatorSubscriptionsEditController | |||||||
|         ->setContinueOnNoEffect(true) |         ->setContinueOnNoEffect(true) | ||||||
|         ->setContentSourceFromRequest($request); |         ->setContentSourceFromRequest($request); | ||||||
|  |  | ||||||
|       $editor->applyTransactions($object, array($xaction)); |       $editor->applyTransactions( | ||||||
|  |         $object->getApplicationTransactionObject(), | ||||||
|  |         array($xaction)); | ||||||
|     } else { |     } else { | ||||||
|  |  | ||||||
|       // TODO: Eventually, get rid of this once everything implements |       // TODO: Eventually, get rid of this once everything implements | ||||||
|   | |||||||
| @@ -1,8 +1,38 @@ | |||||||
| <?php | <?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 { | 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(); |   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(); |   public function getApplicationTransactionObject(); | ||||||
|  |  | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |    * Return a template transaction for this object. | ||||||
|  |    * | ||||||
|  |    * @return PhabricatorApplicationTransaction | ||||||
|  |    */ | ||||||
|  |   public function getApplicationTransactionTemplate(); | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 epriestley
					epriestley