Skip to content

Commit

Permalink
Fix event dispatched on document completion because of asynchronous b…
Browse files Browse the repository at this point in the history
…ehaviour on TM side (#67)
  • Loading branch information
Pierre Ducoudray authored and cdaguerre committed May 25, 2016
1 parent 84d2016 commit 39ca62c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions lib/Textmaster/Model/AbstractObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function save()
final protected function update()
{
$this->data = $this->getApi()->update($this->getId(), $this->data);
$this->dispatchEvent($this->data);
$this->dispatchEvent($this->getStatus(), $this->data);

return $this;
}
Expand All @@ -107,7 +107,7 @@ final protected function update()
final protected function create()
{
$this->data = $this->getApi()->create($this->data);
$this->dispatchEvent($this->data);
$this->dispatchEvent($this->getStatus(), $this->data);

return $this;
}
Expand Down Expand Up @@ -167,14 +167,14 @@ protected function getProperty($property)
/**
* Dispatch an event.
*
* @param array $data Optional data to dispatch with the event.
* @param string $status
* @param array $data Optional data to dispatch with the event.
*/
protected function dispatchEvent(array $data = array())
protected function dispatchEvent($status, array $data = array())
{
$name = $this->getEventNamePrefix().'.'.$this->getStatus();
$name = $this->getEventNamePrefix().'.'.$status;

$event = new GenericEvent($this, $data);

$this->client->getEventDispatcher()->dispatch($name, $event);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Textmaster/Model/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ final public function complete($satisfaction = null, $message = null)
}

$this->data = $this->getApi()->complete($this->getId(), $satisfaction, $message);
$this->dispatchEvent($this->data);
$this->dispatchEvent(DocumentInterface::STATUS_COMPLETED, $this->data);

return $this;
}
Expand Down

0 comments on commit 39ca62c

Please sign in to comment.