You are here

function lingotek_sync_upload_node in Lingotek Translation 7.4

Same name and namespace in other branches
  1. 7.3 lingotek.batch.inc \lingotek_sync_upload_node()

Upload Batch Worker Function: Upload Node for Translation

1 string reference to 'lingotek_sync_upload_node'
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.

File

./lingotek.batch.inc, line 353
Central location for batch create functions, before control is handed off to individual batch command files.

Code

function lingotek_sync_upload_node($nid, &$context) {
  LingotekLog::trace('upload node: @node_id', array(
    '@node_id' => $nid,
  ));
  if ($context) {
    $context['message'] = t('Uploading node @nid for translation', array(
      '@nid' => $nid,
    ));
  }
  $api = LingotekApi::instance();
  $node = lingotek_node_load_default($nid);
  if ($node->lingotek['profile'] == LingotekSync::PROFILE_DISABLED || $node->lingotek['node_sync_status'] == LingotekSync::STATUS_DISABLED) {
    return;
  }

  // clear any node caching by entitycache module
  if (module_exists('entitycache')) {
    cache_clear_all($nid, 'cache_entity_node');
  }

  // Push this node for translation.
  if ($existing_document = isset($node->lingotek['document_id']) ? $node->lingotek['document_id'] : NULL) {

    // Update an existing Lingotek Document.
    $result = $api
      ->updateContentDocument($node);
  }
  else {

    // Create a new Lingotek Document.
    $ln = LingotekNode::load($node);
    lingotek_node_save_readonly($node);
    $result = $api
      ->addContentDocument($ln, TRUE);
  }
  if ($result) {
    $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'][] = $nid;
  }
  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'][] = $nid;
  }

  //$context['results'][] = t('Uploaded: Node #@nid', array('@nid' => $nid));
}