You are here

function lingotek_sync_download_node_target in Lingotek Translation 7.4

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

Download Batch Worker Function: Download Translated Node Content

1 call to lingotek_sync_download_node_target()
lingotek_notifications in ./lingotek.sync.inc
Registers the site translation notfication callback.
2 string references to 'lingotek_sync_download_node_target'
lingotek_get_sync_download_batch_elements in ./lingotek.batch.inc
Sync - Download Batch Elements: Creates the batch elements for nodes/documents that need to be downloaded.
lingotek_grid_download_ready in ./lingotek.bulk_grid.inc

File

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

Code

function lingotek_sync_download_node_target($nid, $lingotek_locale, $sync_success_status, $update_progress = TRUE, &$context) {
  if ($context) {
    $context['message'] = t('Downloading "@locale" translation for node @nid', array(
      '@locale' => $lingotek_locale,
      '@nid' => $nid,
    ));
  }
  $node = lingotek_node_load_default($nid);
  if ($node->language == Lingotek::convertLingotek2Drupal($lingotek_locale)) {
    return;
  }
  LingotekLog::trace('download node: @node_id (@language)', array(
    '@node_id' => $nid,
    '@language' => $lingotek_locale,
  ));
  $status = LingotekSync::getTargetStatus(LingotekSync::getDocIdFromNodeId($nid), $lingotek_locale);
  if ($status == LingotekSync::STATUS_READY || $status == LingotekSync::STATUS_CURRENT) {

    // Overide sync_success_status variable because statuses will be current for all downloads
    $sync_success_status = LingotekSync::STATUS_CURRENT;
  }
  else {
    $sync_success_status = LingotekSync::STATUS_PENDING;
  }
  if ($sync_success_status != LingotekSync::STATUS_CURRENT && $update_progress) {

    //lingotek_get_and_update_target_progress(LingotekSync::getDocIdFromNodeId($nid));
  }
  elseif ($sync_success_status == LingotekSync::STATUS_CURRENT && $update_progress) {
    lingotek_lingonode($nid, 'target_sync_progress_' . $lingotek_locale, 100);
    lingotek_lingonode($nid, 'target_sync_last_progress_updated_' . $lingotek_locale, time());
  }
  $result = lingotek_download_document($node, $lingotek_locale, $sync_success_status);
  cache_clear_all('field:node:' . $nid, 'cache_field');
  if ($result) {
    $context['results']['downloads'] = isset($context['results']['downloads']) && is_numeric($context['results']['downloads']) ? $context['results']['downloads'] + 1 : 1;
    if (!isset($context['results']['downloaded_node_targets']) || !is_array($context['results']['downloaded_node_targets'])) {
      $context['results']['downloaded_node_targets'] = array();
    }
    $context['results']['downloaded_node_targets'][] = array(
      "nid" => $nid,
      "locale" => $lingotek_locale,
    );
  }
  else {
    $context['results']['download_fails'] = isset($context['results']['download_fails']) && is_numeric($context['results']['download_fails']) ? $context['results']['download_fails'] + 1 : 1;
    if (!isset($context['results']['download_fail_node_targets']) || !is_array($context['results']['download_fail_node_targets'])) {
      $context['results']['download_fail_node_targets'] = array();
    }
    $context['results']['download_fail_node_targets'][] = array(
      "nid" => $nid,
      "locale" => $lingotek_locale,
    );
  }
}