function lingotek_node_update in Lingotek Translation 7.2
Same name and namespace in other branches
- 6 lingotek.module \lingotek_node_update()
- 7.3 lingotek.module \lingotek_node_update()
- 7.4 lingotek.module \lingotek_node_update()
Implements hook_node_update().
1 call to lingotek_node_update()
- lingotek_node_insert in ./
lingotek.module - Implements hook_node_insert().
File
- ./
lingotek.module, line 790
Code
function lingotek_node_update($node) {
// If the user explicitly requested that this item not be pushed to Lingotek, set the Lingonode property so that the
// edit form default can be set appropriately on subsequent edits.
$send_lingotek_document = NULL;
if (isset($node->create_lingotek_document)) {
lingotek_lingonode($node->nid, 'create_lingotek_document', $node->create_lingotek_document);
}
if (isset($node->lingotek_push_once) && $node->lingotek_push_once) {
$send_lingotek_document = 1;
}
else {
if (lingotek_managed_by_entity_translation($node->type) && !lingotek_node_pushed($node)) {
$send_lingotek_document = 0;
}
else {
if (isset($node->lingotek_upload_override)) {
// this variable can force to either send or not send (1 or 0) when set.
$send_lingotek_document = $node->lingotek_upload_override == 1 ? 1 : 0;
}
else {
// Only send the node content to Lingotek on edit if auto-upload is enabled.
$send_lingotek_document = lingotek_lingonode($node->nid, 'create_lingotek_document');
if ($send_lingotek_document === FALSE) {
// use global default if node-level setting is not set
$send_lingotek_document = variable_get('lingotek_create_documents_by_default', $send_lingotek_document);
}
}
}
}
if (!lingotek_supported_type($node->type) || !lingotek_supported_language($node->language)) {
return;
}
// On node create or edit, set the node sync status to 'edited' and all the targets to edited.
$is_syncing = isset($node->skip_status_updates) && $node->skip_status_updates ? TRUE : FALSE;
$is_syncing = isset($_SESSION['lingotek_sync_in_progress']) ? $_SESSION['lingotek_sync_in_progress'] : $is_syncing;
if ($is_syncing === FALSE) {
lingotek_set_node_and_targets_sync_status($node->nid, LINGOTEK_NODE_SYNC_STATUS_EDITED, LINGOTEK_TARGET_SYNC_STATUS_EDITED);
}
// Overwrite document ID.
if (user_access('dev') && isset($node->document_id) && is_numeric($node->document_id)) {
lingotek_lingonode($node->nid, 'document_id', $node->document_id);
}
if (isset($node->mtEngine)) {
lingotek_lingonode($node->nid, 'mt_engine', $node->mtEngine);
}
if (user_access('url_alias_translation') && isset($node->urlAliasTranslation)) {
lingotek_lingonode($node->nid, 'url_alias_translation', $node->urlAliasTranslation);
}
if (isset($node->mtTargets)) {
$node->mtTargets = array_filter($node->mtTargets, "lingotek_unselected");
lingotek_lingonode($node->nid, 'mt_targets', implode(",", $node->mtTargets));
}
// Items that are only accessible on node add or edit forms for nodes not yet sent to Lingotek.
if (lingotek_lingonode($node->nid, 'document_id') === FALSE) {
lingotek_trace('lingotek_node_update FIRST RUN ONLY', array(
"nid" => $node->nid,
"language" => $node->language,
));
$project_id = variable_get('lingotek_project', 0);
if (user_access('access per-item lingotek project selection') && !empty($node->lingotek_project_id)) {
$project_id = $node->lingotek_project_id;
}
lingotek_lingonode($node->nid, 'project_id', $project_id);
$vault_id = variable_get('lingotek_vault', '');
if (user_access('access per-item lingotek vault selection') && !empty($node->lingotek_vault_id)) {
$vault_id = $node->lingotek_vault_id;
}
lingotek_lingonode($node->nid, 'vault_id', $vault_id);
if (!empty($node->lingotek_workflow_id)) {
lingotek_lingonode($node->nid, 'workflow_id', $node->lingotek_workflow_id);
}
if ($send_lingotek_document) {
if (LingotekApi::instance()
->addContentDocument($node, TRUE)) {
drupal_set_message(t('<em>@node_title</em> sent to Lingotek successfully.', array(
'@node_title' => $node->title,
)));
}
else {
drupal_set_message(t('Unable to send <em>@node_title</em> to Lingotek.', array(
'@node_title' => $node->title,
)), 'error');
}
}
}
else {
// Keep source document up to date.
$router_item = menu_get_item();
// These are the URLs that should NOT send updates
$skip_list = array(
'lingotek/update',
LINGOTEK_BASE_URL . '/notifications',
);
$path_match = array_search($router_item['path'], $skip_list);
// Also, dont upload if this node update was caused by the sync
$is_syncing = isset($_SESSION['lingotek_sync_in_progress']) ? $_SESSION['lingotek_sync_in_progress'] : FALSE;
if ($send_lingotek_document && $path_match === FALSE && $is_syncing === FALSE) {
LingotekApi::instance()
->updateContentDocument($node);
//LingotekNode::load($node));
}
}
if (isset($node->lingotek_allow_community_translation)) {
lingotek_lingonode($node->nid, 'allow_community_translation', $node->lingotek_allow_community_translation);
}
if (user_access('sync_method') && isset($node->syncMethod)) {
lingotek_lingonode($node->nid, 'sync_method', $node->syncMethod);
//auto-download
}
if (user_access('use_source') && isset($node->useSource)) {
lingotek_lingonode($node->nid, 'use_source', $node->useSource);
}
}