mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-14 00:31:05 +01:00
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
This commit is contained in:
parent
e36721a9cf
commit
b398ae5504
3 changed files with 39 additions and 22 deletions
src/applications/differential
controller
editor
field/specification
|
@ -67,35 +67,15 @@ final class DifferentialRevisionEditController extends DifferentialController {
|
||||||
$is_new = !$revision->getID();
|
$is_new = !$revision->getID();
|
||||||
$user = $request->getUser();
|
$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 = new DifferentialRevisionEditor($revision);
|
||||||
$editor->setActor($request->getUser());
|
$editor->setActor($request->getUser());
|
||||||
if ($diff) {
|
if ($diff) {
|
||||||
$editor->addDiff($diff, $request->getStr('comments'));
|
$editor->addDiff($diff, $request->getStr('comments'));
|
||||||
}
|
}
|
||||||
$editor->setAuxiliaryFields($aux_fields);
|
$editor->setAuxiliaryFields($aux_fields);
|
||||||
|
$editor->setAphrontRequestForEventDispatch($request);
|
||||||
$editor->save();
|
$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())
|
return id(new AphrontRedirectResponse())
|
||||||
->setURI('/D'.$revision->getID());
|
->setURI('/D'.$revision->getID());
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,9 +17,22 @@ final class DifferentialRevisionEditor extends PhabricatorEditor {
|
||||||
|
|
||||||
private $auxiliaryFields = array();
|
private $auxiliaryFields = array();
|
||||||
private $contentSource;
|
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) {
|
public function __construct(DifferentialRevision $revision) {
|
||||||
$this->revision = $revision;
|
$this->revision = $revision;
|
||||||
|
$this->isCreate = !($revision->getID());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function newRevisionFromConduitWithDiff(
|
public static function newRevisionFromConduitWithDiff(
|
||||||
|
@ -844,12 +857,36 @@ final class DifferentialRevisionEditor extends PhabricatorEditor {
|
||||||
foreach ($this->auxiliaryFields as $aux_field) {
|
foreach ($this->auxiliaryFields as $aux_field) {
|
||||||
$aux_field->willWriteRevision($this);
|
$aux_field->willWriteRevision($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->dispatchEvent(
|
||||||
|
PhabricatorEventType::TYPE_DIFFERENTIAL_WILLEDITREVISION);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function didWriteRevision() {
|
private function didWriteRevision() {
|
||||||
foreach ($this->auxiliaryFields as $aux_field) {
|
foreach ($this->auxiliaryFields as $aux_field) {
|
||||||
$aux_field->didWriteRevision($this);
|
$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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -38,7 +38,7 @@ final class DifferentialJIRAIssuesFieldSpecification
|
||||||
->setCaption(
|
->setCaption(
|
||||||
pht('Example: %s', phutil_tag('tt', array(), 'JIS-3, JIS-9')))
|
pht('Example: %s', phutil_tag('tt', array(), 'JIS-3, JIS-9')))
|
||||||
->setName($this->getStorageKey())
|
->setName($this->getStorageKey())
|
||||||
->setValue(implode(', ', $this->value))
|
->setValue(implode(', ', nonempty($this->value, array())))
|
||||||
->setError($this->error);
|
->setError($this->error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue