function lingotek_upload_document in Lingotek Translation 7.4
Same name and namespace in other branches
- 7.3 lingotek.module \lingotek_upload_document()
2 calls to lingotek_upload_document()
- lingotek_node_update in ./
lingotek.module - Implements hook_node_update().
- lingotek_workbench_moderation_transition in ./
lingotek.module - Implements hook_workbench_moderation_transition()
File
- ./
lingotek.module, line 1299
Code
function lingotek_upload_document($node) {
if (!lingotek_supported_type($node->type) && $node->lingotek['profile'] == LingotekSync::PROFILE_DISABLED || !Lingotek::isSupportedLanguage($node->language)) {
return;
}
if (isset($node->lingotek['node_sync_status']) && ($node->lingotek['node_sync_status'] == LingotekSync::STATUS_DISABLED || $node->lingotek['node_sync_status'] == LingotekSync::STATUS_TARGET)) {
return;
}
if (isset($node->lingotek['document_id'])) {
$xml = lingotek_xml_node_body($node);
$hash = md5($xml);
$oldhash = lingotek_lingonode($node->nid, 'hash');
lingotek_lingonode($node->nid, 'hash', $hash);
$diff = strcmp($hash, $oldhash);
if ($diff == 0 && $node->lingotek['node_sync_status'] == 'CURRENT') {
return;
//node has no changes.
}
}
// 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->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;
$node->lingotek_upload_override = 0;
}
else {
$send_lingotek_document = isset($node->lingotek['create_lingotek_document']) ? $node->lingotek['create_lingotek_document'] : FALSE;
}
if ($send_lingotek_document) {
LingotekSync::resetTargetProgress($node->nid);
}
// if workbench moderation is enabled for this node and it is being sent, set flag to be moderated
// prevents moderation from happening for every downloaded language
if ($node->lingotek['sync_method'] == 1 && module_exists('workbench_moderation') && isset($node->workbench_moderation)) {
$moderate = $send_lingotek_document == 1 ? 1 : 0;
if ($moderate) {
lingotek_lingonode($node->nid, 'workbench_moderate', 0);
}
}
// 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) {
LingotekSync::setNodeAndTargetsStatus($node, LingotekSync::STATUS_EDITED, LingotekSync::STATUS_EDITED);
}
// Items that are only accessible on node add or edit forms for nodes not yet sent to Lingotek.
if (!isset($node->lingotek['document_id']) || empty($node->lingotek['document_id'])) {
LingotekLog::trace('lingotek_node_update FIRST RUN ONLY', array(
"nid" => $node->nid,
"language" => $node->language,
));
if ($send_lingotek_document) {
lingotek_node_save_readonly($node);
$ln = LingotekNode::load($node);
if (LingotekApi::instance()
->addContentDocument($ln, 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 {
lingotek_lingonode($node->nid, 'node_sync_status', LingotekSync::STATUS_EDITED);
}
}
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_MENU_LANG_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);
}
else {
lingotek_lingonode($node->nid, 'node_sync_status', LingotekSync::STATUS_EDITED);
}
}
}