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); }