From 473a2c3b317b6d7a3665143cec6c97435df18ae9 Mon Sep 17 00:00:00 2001 From: Afaque Hussain Date: Fri, 24 May 2013 06:38:54 -0700 Subject: [PATCH] Added willEditTask and didEditTask for Differential. Summary: Added constants to PhabricatorEventType. Modified DifferentialRevisionEditor and DifferentialCommentEditor. Test Plan: Created a revision. Edited and made a comment on that revision. It's updating as usual. I think nothing broke may be it's working. Let me know if I have done it correclty. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin, AnhNhan Maniphest Tasks: T2899 Differential Revision: https://secure.phabricator.com/D5869 --- .../DifferentialRevisionEditController.php | 24 +++++++++++++++ .../editor/DifferentialCommentEditor.php | 21 +++++++++++++ src/docs/userguide/events.diviner | 30 ++++++++++++++++++- .../events/constant/PhabricatorEventType.php | 2 ++ 4 files changed, 76 insertions(+), 1 deletion(-) diff --git a/src/applications/differential/controller/DifferentialRevisionEditController.php b/src/applications/differential/controller/DifferentialRevisionEditController.php index c715879cf9..f2234f866e 100644 --- a/src/applications/differential/controller/DifferentialRevisionEditController.php +++ b/src/applications/differential/controller/DifferentialRevisionEditController.php @@ -56,6 +56,20 @@ final class DifferentialRevisionEditController extends DifferentialController { } if (!$errors) { + $is_new = !$revision->getID(); + $user = $request->getUser(); + + $event = new PhabricatorEvent( + PhabricatorEventType::TYPE_DIFFERENTIAL_WILLEDITREVISION, + array( + 'revision' => $revision, + 'new' => $is_new, + )); + + $event->setUser($user); + $event->setAphrontRequest($request); + PhutilEventEngine::dispatchEvent($event); + $editor = new DifferentialRevisionEditor($revision); $editor->setActor($request->getUser()); if ($diff) { @@ -64,6 +78,16 @@ final class DifferentialRevisionEditController extends DifferentialController { $editor->setAuxiliaryFields($aux_fields); $editor->save(); + $event = new PhabricatorEvent( + PhabricatorEventType::TYPE_DIFFERENTIAL_DIDEDITREVISION, + array( + 'revision' => $revision, + 'new' => $is_new, + )); + $event->setUser($user); + $event->setAphrontRequest($request); + PhutilEventEngine::dispatchEvent($event); + return id(new AphrontRedirectResponse()) ->setURI('/D'.$revision->getID()); } diff --git a/src/applications/differential/editor/DifferentialCommentEditor.php b/src/applications/differential/editor/DifferentialCommentEditor.php index 240deda2bc..b285a8cdc8 100644 --- a/src/applications/differential/editor/DifferentialCommentEditor.php +++ b/src/applications/differential/editor/DifferentialCommentEditor.php @@ -492,6 +492,18 @@ final class DifferentialCommentEditor extends PhabricatorEditor { $actor_phid); } + $is_new = !$revision->getID(); + + $event = new PhabricatorEvent( + PhabricatorEventType::TYPE_DIFFERENTIAL_WILLEDITREVISION, + array( + 'revision' => $revision, + 'new' => $is_new, + )); + + $event->setUser($actor); + PhutilEventEngine::dispatchEvent($event); + $comment = id(new DifferentialComment()) ->setAuthorPHID($actor_phid) ->setRevisionID($revision->getID()) @@ -546,6 +558,15 @@ final class DifferentialCommentEditor extends PhabricatorEditor { $comment->setMetadata($metadata); $comment->save(); + + $event = new PhabricatorEvent( + PhabricatorEventType::TYPE_DIFFERENTIAL_DIDEDITREVISION, + array( + 'revision' => $revision, + 'new' => $is_new, + )); + $event->setUser($actor); + PhutilEventEngine::dispatchEvent($event); } } diff --git a/src/docs/userguide/events.diviner b/src/docs/userguide/events.diviner index ddf7bff98f..07f0f39b63 100644 --- a/src/docs/userguide/events.diviner +++ b/src/docs/userguide/events.diviner @@ -204,6 +204,34 @@ doesn't need to be reviewed) or not. Data available on this event: - ##is_generated## Boolean indicating if this file should be treated as generated. +== Differential: Will Edit Revision == + +The constant for this event is +`PhabricatorEventType::TYPE_DIFFERENTIAL_WILLEDITREVISION`. + +This event is dispatched before a revision is edited, and allows you to +respond to or alter the edit. Data available on this event: + + - ##revision## The @{class:DifferentialRevision} being edited. + - ##new## A boolean indicating if this revision is being created. + +This is similar to the next event (did edit revision) but occurs before the edit +begins. + +== Differential: Did Edit Revision == + +The constant for this event is +`PhabricatorEventType::TYPE_DIFFERENTIAL_DIDEDITREVISION`. + +This event is dispatched after a revision is edited, and allows you to +react to the edit. Data available on this event: + + - ##revision## The @{class:DifferentialRevision} being edited. + - ##new## A boolean indicating if this revision is being created. + +This is similar to the previous event (will edit revision) but occurs after the +edit completes. + == Diffusion: Did Discover Commit == The constant for this event is @@ -336,4 +364,4 @@ If you're having problems with your listener, try these steps: Continue by: - taking a look at @{class:PhabricatorExampleEventListener}; or - - building a library with @{article:libphutil Libraries User Guide}. \ No newline at end of file + - building a library with @{article:libphutil Libraries User Guide}. diff --git a/src/infrastructure/events/constant/PhabricatorEventType.php b/src/infrastructure/events/constant/PhabricatorEventType.php index 20e7b688ad..3d35e00476 100644 --- a/src/infrastructure/events/constant/PhabricatorEventType.php +++ b/src/infrastructure/events/constant/PhabricatorEventType.php @@ -15,6 +15,8 @@ final class PhabricatorEventType extends PhutilEventType { const TYPE_DIFFERENTIAL_WILLSENDMAIL = 'differential.willSendMail'; const TYPE_DIFFERENTIAL_WILLMARKGENERATED = 'differential.willMarkGenerated'; + const TYPE_DIFFERENTIAL_WILLEDITREVISION = 'differential.willEditRevision'; + const TYPE_DIFFERENTIAL_DIDEDITREVISION = 'differential.didEditRevision'; const TYPE_DIFFUSION_DIDDISCOVERCOMMIT = 'diffusion.didDiscoverCommit'; const TYPE_DIFFUSION_LOOKUPUSER = 'diffusion.lookupUser';