You are here

function lingotek_sync_batch_create_old in Lingotek Translation 7.2

Same name and namespace in other branches
  1. 7.3 lingotek.batch.inc \lingotek_sync_batch_create_old()
1 call to lingotek_sync_batch_create_old()
lingotek_sync in ./lingotek.sync.inc
The main function responsible for syncing node/document translation.

File

./lingotek.batch.inc, line 108

Code

function lingotek_sync_batch_create_old() {

  // Grab the Nodes that need to be Downloaded & Uploaded.  These are batch operation arrays.
  $download_commands = lingotek_get_sync_download_batch_elements();
  $upload_commands = lingotek_get_sync_upload_batch_elements();

  // Important: Until we add the call to get target statuses, and can work off that, do the upload SECOND. (so we dont try to download what we just uploaded.)
  $operations = array();
  $operations[] = array(
    'lingotek_mt_sync_set_status',
    array(
      'set',
    ),
  );
  $operations = array_merge($operations, $download_commands, $upload_commands);
  $operations[] = array(
    'lingotek_mt_sync_set_status',
    array(
      'clear',
    ),
  );

  // Where to send the user after the batch has processed. If redirect_url GET param exists, then use it
  $redirect = isset($_GET['redirect_url']) && strlen($_GET['redirect_url']) ? $_GET['redirect_url'] : LINGOTEK_BASE_URL;
  if (count($operations) > 0) {

    // Note, the first step of the batch process sets a session variable that tracks that we are in a sync state.
    // The Node update hook uses that so it knows NOT to reupload the content we just recieved.
    // The last step of the sync process clears the sync flag.   $_SESSION['lingotek_sync_in_progress']
    // As a backup (in case there is an error and the batch doesnt complete successfully) there is a backup on the lingotek_dashboard() that clears the sync status flag.
    $batch = array(
      'title' => t('Syncing Content Translations with Lingotek'),
      'operations' => $operations,
      'file' => drupal_get_path('module', 'lingotek') . '/lib/Drupal/batch/lingotek.mt.batch.sync.inc',
    );
    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);
  }
}