You are here

function lingotek_get_sync_download_batch_elements in Lingotek Translation 7.3

Same name and namespace in other branches
  1. 7.7 lingotek.batch.inc \lingotek_get_sync_download_batch_elements()
  2. 7.2 lingotek.batch.inc \lingotek_get_sync_download_batch_elements()
  3. 7.4 lingotek.batch.inc \lingotek_get_sync_download_batch_elements()
  4. 7.5 lingotek.batch.inc \lingotek_get_sync_download_batch_elements()
  5. 7.6 lingotek.batch.inc \lingotek_get_sync_download_batch_elements()

Sync - Download Batch Elements: Creates the batch elements for nodes/documents that need to be downloaded.

Parameters

download_targets : list of objects (document_id, lingotek_locale) //json_decode([ {"document_id": "191", "locale": "fr_FR" }, ... ]);

2 calls to lingotek_get_sync_download_batch_elements()
lingotek_sync_batch_create in ./lingotek.batch.inc
Batch Create - Sync: Uploads new and changed documents for translation and Downloads translated documents.
lingotek_sync_batch_create_old in ./lingotek.batch.inc

File

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

Code

function lingotek_get_sync_download_batch_elements($download_targets = NULL, $sync_success_target = LingotekSync::STATUS_CURRENT) {
  $operations = array();
  if (is_null($download_targets)) {
    $target_locales = lingotek_get_target_locales();
    foreach ($target_locales as $lingotek_locale) {

      // get all nodes that have pending translations
      $key = 'target_sync_status_' . $lingotek_locale;
      $query = db_select('lingotek', 'l')
        ->fields('l');
      $query
        ->condition('lingokey', $key);
      $query
        ->condition('lingovalue', LingotekSync::STATUS_PENDING);
      $result = $query
        ->execute();
      while ($record = $result
        ->fetchAssoc()) {
        $operations[] = array(
          'lingotek_sync_download_node_target',
          array(
            $record['nid'],
            $lingotek_locale,
            $sync_success_target,
          ),
        );
      }

      // get all config chunks that have pending translations
      $key = 'target_sync_status_' . $lingotek_locale;
      $query = db_select('lingotek_config_metadata', 'meta')
        ->fields('meta');
      $query
        ->condition('config_key', $key);
      $query
        ->condition('value', LingotekSync::STATUS_PENDING);
      $result = $query
        ->execute();
      while ($record = $result
        ->fetchAssoc()) {
        $operations[] = array(
          'lingotek_sync_download_chunk_target',
          array(
            $record['id'],
            $lingotek_locale,
            $sync_success_target,
          ),
        );
      }
    }
  }
  elseif (is_array($download_targets)) {
    foreach ($download_targets as $download_target) {
      $nid = LingotekSync::getNodeIdFromDocId($download_target->document_id);
      if ($nid != NULL) {
        $lingotek_locale = $download_target->locale;
        $operations[] = array(
          'lingotek_sync_download_node_target',
          array(
            $nid,
            $lingotek_locale,
            $sync_success_target,
          ),
        );
      }
      else {

        // since no node was found associated with the document ID, check config chunks
        $cid = LingotekConfigChunk::getIdByDocId($download_target->document_id);
        if ($cid) {
          $lingotek_locale = $download_target->locale;
          $operations[] = array(
            'lingotek_sync_download_chunk_target',
            array(
              $cid,
              $lingotek_locale,
              $sync_success_target,
            ),
          );
        }
      }
    }
  }
  return $operations;
}