function lingotek_notifications in Lingotek Translation 7.5
Same name and namespace in other branches
- 7.7 lingotek.sync.inc \lingotek_notifications()
- 7.2 lingotek.sync.inc \lingotek_notifications()
- 7.3 lingotek.sync.inc \lingotek_notifications()
- 7.4 lingotek.sync.inc \lingotek_notifications()
- 7.6 lingotek.sync.inc \lingotek_notifications()
Registers the site translation notfication callback.
1 string reference to 'lingotek_notifications'
- lingotek_menu in ./
lingotek.module - Implements hook_menu().
File
- ./
lingotek.sync.inc, line 95 - Sync and management
Code
function lingotek_notifications() {
drupal_page_is_cacheable(FALSE);
LingotekLog::trace('Received <pre>@data</pre>', array(
'@data' => var_export($_GET, TRUE),
), 'callback');
$document_id = isset($_GET['doc_id']) ? $_GET['doc_id'] : NULL;
// uuid
$document_idx = isset($_GET['doc_idx']) ? $_GET['doc_idx'] : NULL;
// this is the deprecated document number
$lingotek_locale = isset($_GET['target_code']) ? $_GET['target_code'] : NULL;
$project_id = isset($_GET['project_id']) ? $_GET['project_id'] : NULL;
$completed = isset($_GET['completed']) ? $_GET['completed'] : 1;
$security_token = isset($_GET['security_token']) ? $_GET['security_token'] : NULL;
$stored_security_token = variable_get('lingotek_notify_security_token', NULL);
if (!is_null($stored_security_token)) {
// only enforce security token matching if set as variable
if (strcmp($security_token, $stored_security_token) != 0) {
return drupal_json_output(array(
"message" => "Invalid security token",
));
}
}
if (!isset($document_id) && !isset($document_idx) || !isset($lingotek_locale)) {
return drupal_json_output(array(
"message" => "Missing Required Parameter(s). Required: doc_id, target_code",
));
}
include_once 'lingotek.batch.inc';
$target_drupal_language_code = Lingotek::convertLingotek2Drupal($lingotek_locale);
$trans_obj = lingotek_get_trans_obj($document_id, $document_idx);
$downloaded = FALSE;
if ($trans_obj) {
$trans_obj
->preDownload($lingotek_locale, $completed);
$replacements = array(
'@trans_type' => get_class($trans_obj),
'@document' => $document_id,
'@language_code' => $lingotek_locale,
'@project_id' => $project_id,
'@id' => $trans_obj
->getId(),
);
if ($downloaded = $trans_obj
->downloadTriggered($lingotek_locale)) {
LingotekLog::trace('Updated local content for <strong>@trans_type</strong> @id based on hit
from external API for document: @document, language code @language_code, project ID: @project_id', $replacements, 'api');
}
else {
LingotekLog::trace('Unable to update local content for <strong>@trans_type</strong> @id based on hit
from external API for document: @document, language code @language_code, project ID: @project_id', $replacements, 'api');
}
$trans_obj
->postDownload($lingotek_locale, $completed);
}
else {
LingotekLog::error('Lingotek document ID (@doc_id) not found.', array(
'@doc_id' => $document_id,
));
return drupal_json_output(array(
"message" => "The doc_id was not found on the site.",
));
}
LingotekLog::info('[notify] <br/><b>code:</b> @lingotek_locale <br/><b>doc_id:</b> @document_id<br/><b>project:</b> @project_id <br/><b>entity:</b> @entity_type #@entity_id (@target_drupal_language_code) <br/><b>completed</b>: @completed', array(
'@document_id' => $document_id,
'@lingotek_locale' => $lingotek_locale,
'@project_id' => $project_id,
'@target_drupal_language_code' => $target_drupal_language_code,
'@entity_type' => isset($trans_obj) ? $trans_obj
->getEntityType() : '',
'@entity_id' => isset($trans_obj) ? $trans_obj
->getId() : '',
'@completed' => $completed,
), 'callback');
$found = isset($trans_obj) && $trans_obj;
$response = array_merge($_GET, array(
'target_drupal_language_code' => $target_drupal_language_code,
'type' => isset($trans_obj) ? $trans_obj
->getEntityType() : '',
'id' => isset($trans_obj) ? $trans_obj
->getId() : '',
'found' => $found,
'download' => $downloaded,
));
return drupal_json_output($response);
}