You are here

function lingotek_get_sync_download_batch_elements in Lingotek Translation 7.4

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.3 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_grid_action_submit in ./lingotek.bulk_grid.inc
Submit function for The Grid's actions The action corresponds to the key of the option selected Often redirects to batch operations or to other pages entirely
lingotek_sync_batch_create in ./lingotek.batch.inc
Batch Create - Sync: Uploads new and changed documents for translation and Downloads translated documents.

File

./lingotek.batch.inc, line 186
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);
      $status_or = db_or()
        ->condition('lingovalue', LingotekSync::STATUS_PENDING)
        ->condition('lingovalue', LingotekSync::STATUS_READY);
      $query
        ->condition($status_or);
      $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);
      $status_or = db_or()
        ->condition('value', LingotekSync::STATUS_PENDING)
        ->condition('value', LingotekSync::STATUS_READY);
      $query
        ->condition($status_or);
      $result = $query
        ->execute();
      $ran = FALSE;
      while ($record = $result
        ->fetchAssoc()) {
        $ran = TRUE;
        $operations[] = array(
          'lingotek_sync_download_chunk_target',
          array(
            $record['id'],
            $lingotek_locale,
            $sync_success_target,
          ),
        );
      }
      if ($ran) {
        $operations[] = array(
          'drupal_flush_all_caches',
          array(),
        );
      }
    }
  }
  elseif (is_array($download_targets)) {
    $doc_ids = array();
    $updates = array();
    foreach ($download_targets as $download_target) {
      $nid = LingotekSync::getNodeIdFromDocId($download_target->document_id);
      if ($nid != NULL) {
        $lingotek_locale = $download_target->locale;
        $doc_ids[] = $download_target->document_id;
        $operations[] = array(
          'lingotek_sync_download_node_target',
          array(
            $nid,
            $lingotek_locale,
            $sync_success_target,
            FALSE,
          ),
        );
      }
      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,
            ),
          );
        }
      }
    }
    $doc_ids = array_unique($doc_ids);
    foreach ($doc_ids as $doc_id) {

      //$updates[] = array('lingotek_get_and_update_target_progress', array($doc_ids));
    }
    $operations = array_merge($updates, $operations);
  }
  return $operations;
}