From b398ae55045149b2780b69785566f571855fce6e Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 16 Sep 2013 08:04:14 -0700 Subject: [PATCH] Dispatch Differential edit events from Editor, not Controller Summary: Currently, these events don't fire for Conduit updates, which makes them sort of silly. This will get proper treatment after T2222. Test Plan: Installed a `throw new Exception(...)` event listener. Performed Conduit and web updates of revisions, saw event listener fire. Reviewers: btrahan, guywarner Reviewed By: guywarner CC: aran Differential Revision: https://secure.phabricator.com/D7004 --- .../DifferentialRevisionEditController.php | 22 +---------- .../editor/DifferentialRevisionEditor.php | 37 +++++++++++++++++++ ...fferentialJIRAIssuesFieldSpecification.php | 2 +- 3 files changed, 39 insertions(+), 22 deletions(-) diff --git a/src/applications/differential/controller/DifferentialRevisionEditController.php b/src/applications/differential/controller/DifferentialRevisionEditController.php index 3d80481be2..1a8e13d693 100644 --- a/src/applications/differential/controller/DifferentialRevisionEditController.php +++ b/src/applications/differential/controller/DifferentialRevisionEditController.php @@ -67,35 +67,15 @@ final class DifferentialRevisionEditController extends DifferentialController { $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) { $editor->addDiff($diff, $request->getStr('comments')); } $editor->setAuxiliaryFields($aux_fields); + $editor->setAphrontRequestForEventDispatch($request); $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/DifferentialRevisionEditor.php b/src/applications/differential/editor/DifferentialRevisionEditor.php index 82b3aebd79..3c68db489a 100644 --- a/src/applications/differential/editor/DifferentialRevisionEditor.php +++ b/src/applications/differential/editor/DifferentialRevisionEditor.php @@ -17,9 +17,22 @@ final class DifferentialRevisionEditor extends PhabricatorEditor { private $auxiliaryFields = array(); private $contentSource; + private $isCreate; + private $aphrontRequestForEventDispatch; + + + public function setAphrontRequestForEventDispatch(AphrontRequest $request) { + $this->aphrontRequestForEventDispatch = $request; + return $this; + } + + public function getAphrontRequestForEventDispatch() { + return $this->aphrontRequestForEventDispatch; + } public function __construct(DifferentialRevision $revision) { $this->revision = $revision; + $this->isCreate = !($revision->getID()); } public static function newRevisionFromConduitWithDiff( @@ -844,12 +857,36 @@ final class DifferentialRevisionEditor extends PhabricatorEditor { foreach ($this->auxiliaryFields as $aux_field) { $aux_field->willWriteRevision($this); } + + $this->dispatchEvent( + PhabricatorEventType::TYPE_DIFFERENTIAL_WILLEDITREVISION); } private function didWriteRevision() { foreach ($this->auxiliaryFields as $aux_field) { $aux_field->didWriteRevision($this); } + + $this->dispatchEvent( + PhabricatorEventType::TYPE_DIFFERENTIAL_DIDEDITREVISION); + } + + private function dispatchEvent($type) { + $event = new PhabricatorEvent( + $type, + array( + 'revision' => $this->revision, + 'new' => $this->isCreate, + )); + + $event->setUser($this->getActor()); + + $request = $this->getAphrontRequestForEventDispatch(); + if ($request) { + $event->setAphrontRequest($request); + } + + PhutilEventEngine::dispatchEvent($event); } /** diff --git a/src/applications/differential/field/specification/DifferentialJIRAIssuesFieldSpecification.php b/src/applications/differential/field/specification/DifferentialJIRAIssuesFieldSpecification.php index 5d55de51c1..0bd42805f5 100644 --- a/src/applications/differential/field/specification/DifferentialJIRAIssuesFieldSpecification.php +++ b/src/applications/differential/field/specification/DifferentialJIRAIssuesFieldSpecification.php @@ -38,7 +38,7 @@ final class DifferentialJIRAIssuesFieldSpecification ->setCaption( pht('Example: %s', phutil_tag('tt', array(), 'JIS-3, JIS-9'))) ->setName($this->getStorageKey()) - ->setValue(implode(', ', $this->value)) + ->setValue(implode(', ', nonempty($this->value, array()))) ->setError($this->error); }