private function LingotekApi::upload_language_specific_targets in Lingotek Translation 7.7
Waits until document import status is complete, then adds targets, or logs an error
1 call to LingotekApi::upload_language_specific_targets()
- LingotekApi::addContentDocument in lib/
Drupal/ lingotek/ LingotekApi.php - Add a document to the Lingotek platform.
File
- lib/
Drupal/ lingotek/ LingotekApi.php, line 218 - Defines Drupal\lingotek\LingotekApi
Class
- LingotekApi
- @file Defines Drupal\lingotek\LingotekApi
Code
private function upload_language_specific_targets($entity_type, $entity_id, $doc_id, $targets) {
$params = array(
'id' => $doc_id,
);
for ($i = 0; $i <= 10; $i++) {
$response = $this
->request('getDocumentImportStatus', $params);
if ($response->status === 'COMPLETE') {
break;
}
elseif ($i > 9) {
drupal_set_message(t('Uploading some language-specific targets failed because of network timeout. Please use the "Request language-specific translations" bulk action.'), 'warning', FALSE);
LingotekLog::error('Adding language-specific targets failed for document ID @id.', array(
'@id' => $doc_id,
));
foreach ($targets as $target_locale => $target_info) {
lingotek_keystore($entity_type, $entity_id, 'target_sync_status_' . $target_locale, LingotekSync::STATUS_ERROR);
}
// Store the failed language-specific targets
LingotekSync::lingotek_store_failed_language_specific_targets($entity_type, $entity_id);
return;
}
else {
sleep(3);
}
}
// The document has been imported successfully, now add the targets
if (is_array($targets)) {
foreach ($targets as $target_locale => $target_attribs) {
if (!empty($doc_id) && !empty($target_attribs['workflow_id'])) {
$tl_result = $this
->addTranslationTarget($doc_id, NULL, $target_locale, $target_attribs['workflow_id']);
if ($tl_result) {
lingotek_keystore($entity_type, $entity_id, 'target_sync_status_' . $target_locale, LingotekSync::STATUS_PENDING);
}
else {
lingotek_keystore($entity_type, $entity_id, 'target_sync_status_' . $target_locale, LingotekSync::STATUS_ERROR);
}
}
}
}
}