Skip to content

Commit

Permalink
Fix translation memory constant name (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Ducoudray authored and cdaguerre committed Dec 15, 2016
1 parent ba3e073 commit dec7c31
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
15 changes: 10 additions & 5 deletions lib/Textmaster/CallbackHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,20 @@ public function handleWebHook(Request $request = null)
}

$data = json_decode($request->getContent(), true);
$event = $this->getEvent($data);
$event = $this->getEvent($data, $request->get('event'));

$this->dispatcher->dispatch($event->getName(), $event);
}

/**
* Get event name and object from request data.
* Get event from request data.
*
* @param array $data
* @param array $data
* @param string|null $event
*
* @return CallbackEvent
*/
private function getEvent(array $data)
private function getEvent(array $data, $event = null)
{
if (array_key_exists('name', $data)) {
$type = 'project';
Expand All @@ -110,7 +111,11 @@ private function getEvent(array $data)
throw new InvalidArgumentException(sprintf('Could not determine callback type from "%s".', serialize($data)));
}

$name = sprintf('textmaster.%s.%s', $type, $data['status']);
if (null === $event) {
$event = $data['status'];
}

$name = sprintf('textmaster.%s.%s', $type, $event);
$resource = new $this->classes[$type]($this->client, $data);

return new CallbackEvent($name, $resource, $data);
Expand Down
4 changes: 2 additions & 2 deletions lib/Textmaster/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ final class Events
* Triggered when project option "translation_memory" is completed.
* Useful for asynchronous launching.
*/
const PROJECT_TM_COMPLETED = 'textmaster.project.tm_completed';
const PROJECT_MEMORY_COMPLETED = 'textmaster.project.tm_completed';

/**
* Get all existing events for documents.
Expand Down Expand Up @@ -164,7 +164,7 @@ public static function getProjectEvents()
{
return [
self::PROJECT_IN_PROGRESS,
self::PROJECT_TM_COMPLETED,
self::PROJECT_MEMORY_COMPLETED,
];
}
}
2 changes: 1 addition & 1 deletion lib/Textmaster/Model/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public static function getAllowedCallbacks()
{
return [
self::CALLBACK_PROJECT_IN_PROGRESS,
self::CALLBACK_PROJECT_TM_COMPLETED,
self::CALLBACK_PROJECT_MEMORY_COMPLETED,
];
}

Expand Down
3 changes: 2 additions & 1 deletion lib/Textmaster/Model/ProjectInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ interface ProjectInterface extends AbstractObjectInterface
const ACTIVITY_PROOFREADING = 'proofreading';

const STATUS_IN_CREATION = 'in_creation';
const STATUS_MEMORY_COMPLETED = 'tm_completed';
const STATUS_IN_PROGRESS = 'in_progress';
const STATUS_IN_REVIEW = 'in_review';
const STATUS_COMPLETED = 'completed';
const STATUS_PAUSED = 'paused';
const STATUS_CANCELED = 'canceled';

const CALLBACK_PROJECT_IN_PROGRESS = 'project_in_progress';
const CALLBACK_PROJECT_TM_COMPLETED = 'project_tm_completed';
const CALLBACK_PROJECT_MEMORY_COMPLETED = 'project_tm_completed';

/**
* Save the project.
Expand Down

0 comments on commit dec7c31

Please sign in to comment.