1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 14:00:56 +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:
epriestley 2013-09-16 08:04:14 -07:00
parent e36721a9cf
commit b398ae5504
3 changed files with 39 additions and 22 deletions

View file

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

View file

@ -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);
}
/**

View file

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