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;
      
    }
  }
  
  $send_lingotek_document = NULL;
  if (isset($node->lingotek_upload_override)) {
    
    $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 ($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);
    }
  }
  
  $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);
  }
  
  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 {
    
    $router_item = menu_get_item();
    
    $skip_list = array(
      'lingotek/update',
      LINGOTEK_MENU_LANG_BASE_URL . '/notifications',
    );
    $path_match = array_search($router_item['path'], $skip_list);
    
    $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);
    }
  }
}