function lingotek_entity_upload in Lingotek Translation 7.5
Same name and namespace in other branches
- 7.7 lingotek.module \lingotek_entity_upload()
- 7.6 lingotek.module \lingotek_entity_upload()
3 calls to lingotek_entity_upload()
- lingotek_entity_upload_triggered in ./
lingotek.module - lingotek_push_form_submit in ./
lingotek.page.inc - Submit handler for the lingotek_push_form form.
- lingotek_rules_entity_upload in ./
lingotek.rules.inc
2 string references to 'lingotek_entity_upload'
- lingotek_get_sync_upload_batch_elements in ./
lingotek.batch.inc - Sync - Upload Batch Elements: Creates the batch elements for nodes/documents that need to be uploaded.
- lingotek_grid_upload_edited in ./
lingotek.bulk_grid.inc
File
- ./
lingotek.module, line 1432
Code
function lingotek_entity_upload($entity, $entity_type, &$context = array()) {
if (is_numeric($entity)) {
$entity = lingotek_entity_load_single($entity_type, $entity);
}
// Exclude translated nodes (targets) created using node-based translation.
if ($entity_type == 'node' && $entity->tnid != 0 && $entity->tnid != $entity->nid) {
LingotekLog::trace('Skipping upload of node @id, since it is a translation target.', array(
'@id' => $entity->nid,
));
return;
}
list($id, $vid, $bundle) = lingotek_entity_extract_ids($entity_type, $entity);
LingotekLog::trace('Uploading @type @id for translation', array(
'@type' => $entity_type,
'@id' => $id,
));
$empty_context = FALSE;
if (empty($context)) {
$empty_context = TRUE;
// preserve the fact that $context *was* empty when passed
$context['message'] = t('Uploading @type @id for translation', array(
'@type' => $entity_type,
'@id' => $id,
));
}
if ($entity->lingotek['profile'] == LingotekSync::PROFILE_DISABLED) {
$context['results']['disabled'][] = $id;
return;
}
if (module_exists('rules')) {
rules_invoke_event('lingotek_entity_pre_upload', new EntityDrupalWrapper($entity_type, $entity));
}
// Items that are only accessible on node add or edit forms for nodes not yet sent to Lingotek.
$ln = LingotekEntity::load($entity, $entity_type);
$entity_has_doc_id = $ln
->getMetadataValue('document_id');
module_invoke_all('lingotek_pre_upload', $ln);
if ($entity_has_doc_id) {
$success = LingotekApi::instance()
->updateContentDocument($ln);
}
else {
$success = LingotekApi::instance()
->addContentDocument($ln, TRUE);
}
if ($empty_context) {
if ($success) {
drupal_set_message(t('<em>@node_title</em> sent to Lingotek successfully.', array(
'@node_title' => $ln
->getTitle(),
)));
lingotek_keystore($entity_type, $id, 'node_sync_status', LingotekSync::STATUS_CURRENT);
}
else {
drupal_set_message(t('Unable to send <em>@node_title</em> to Lingotek.', array(
'@node_title' => $ln
->getTitle(),
)), 'error');
}
}
else {
if ($success) {
$context['results']['uploads'] = isset($context['results']['uploads']) && is_numeric($context['results']['uploads']) ? $context['results']['uploads'] + 1 : 1;
if (!isset($context['results']['uploaded_nids']) || !is_array($context['results']['uploaded_nids'])) {
$context['results']['uploaded_nids'] = array();
}
$context['results']['uploaded_nids'][] = $id;
lingotek_keystore($entity_type, $id, 'node_sync_status', LingotekSync::STATUS_CURRENT);
}
else {
$context['results']['upload_fails'] = isset($context['results']['upload_fails']) && is_numeric($context['results']['upload_fails']) ? $context['results']['upload_fails'] + 1 : 1;
if (!isset($context['results']['upload_fail_nids']) || !is_array($context['results']['upload_fail_nids'])) {
$context['results']['upload_fail_nids'] = array();
}
$context['results']['upload_fail_nids'][] = $id;
}
}
lingotek_keystore($entity_type, $id, 'last_uploaded', time());
$source = isset($entity->language) ? $entity->language : language_default()->language;
$source = Lingotek::convertDrupal2Lingotek($source);
$languages = Lingotek::getLanguagesWithoutSource($source);
// Add pending statuses for all languages on successful upload only
if ($success) {
foreach ($languages as $lingotek_locale) {
lingotek_keystore($entity_type, $id, 'target_sync_status_' . $lingotek_locale, LingotekSync::STATUS_PENDING);
}
}
if (module_exists('entitycache')) {
cache_clear_all($id, 'cache_entity_node');
}
if (module_exists('rules')) {
rules_invoke_event('lingotek_entity_post_upload', new EntityDrupalWrapper($entity_type, $entity));
}
}