You are here

function lingotek_sync_batch_create in Lingotek Translation 7.6

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

Batch Create - Sync: Uploads new and changed documents for translation and Downloads translated documents.

Creates the batch operations array. Downloads first, then uploads.

1 call to lingotek_sync_batch_create()
lingotek_download_translations_form_submit in ./lingotek.page.inc
Download Translations Form Submit

File

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

Code

function lingotek_sync_batch_create($upload_config = array(), $download_targets = array(), $download_targets_incomplete = array(), $redirect = '', $extra_operations = array()) {
  $has_upload_config = !empty($upload_config);
  $has_download = !empty($download_targets);
  $has_download_incomplete = !empty($download_targets_incomplete);

  // Grab the Nodes that need to be Downloaded & Uploaded.  These are batch operation arrays.
  $download_commands = $has_download ? lingotek_get_sync_download_batch_elements($download_targets, LingotekSync::STATUS_CURRENT) : array();
  $download_commands_inc = $has_download_incomplete ? lingotek_get_sync_download_batch_elements($download_targets_incomplete, LingotekSync::STATUS_PENDING) : array();
  $upload_config_commands = $has_upload_config ? lingotek_get_sync_upload_config_batch_elements($upload_config) : array();
  $operations = array();
  $operations = array_merge($operations, $download_commands, $download_commands_inc, $upload_config_commands);
  $operations = array_merge($operations, $extra_operations);

  // Where to send the user after the batch has processed. If redirect_url GET param exists, then use it
  if (empty($redirect)) {
    $redirect = isset($_GET['redirect_url']) && strlen($_GET['redirect_url']) ? $_GET['redirect_url'] : LINGOTEK_MENU_LANG_BASE_URL;
  }
  if (count($operations) > 0) {
    $batch = array(
      'title' => t('Syncing Content and Translations'),
      'operations' => $operations,
      'file' => 'lingotek.batch.inc',
      'finished' => 'lingotek_sync_batch_finished',
    );
    batch_set($batch);
    batch_process($redirect);

    // Needed if not inside a form _submit handler.  Setting redirect in batch_process.
  }
  else {
    $options = strpos($redirect, '//') !== FALSE ? array(
      'external' => TRUE,
    ) : array();
    drupal_goto($redirect, $options);
  }
}