You are here

function lingotek_sync_upload_config_chunk in Lingotek Translation 7.5

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

Upload Batch Worker Function: Upload Config Chunk for Translation

1 string reference to 'lingotek_sync_upload_config_chunk'
lingotek_get_sync_upload_config_batch_elements in ./lingotek.batch.inc
Sync - Upload Config Batch Elements: Creates the batch elements for config (ie. menus, taxonomies, etc.), that need to be uploaded.

File

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

Code

function lingotek_sync_upload_config_chunk($cid, &$context) {
  LingotekLog::trace('upload config chunk: @chunk_id', array(
    '@chunk_id' => $cid,
  ));
  if ($context) {
    $context['message'] = t('Uploading configuration set @cid for translation', array(
      '@cid' => $cid,
    ));
  }
  $api = LingotekApi::instance();
  $chunk = LingotekSync::getConfigChunk($cid);
  module_invoke_all('lingotek_pre_upload', $chunk);

  // Push this chunk for translation.
  if ($existing_document = $chunk
    ->hasLingotekDocId()) {
    LingotekLog::trace('existing document: @existing', array(
      '@existing' => $existing_document,
    ));

    // Update an existing Lingotek Document.
    $result = $api
      ->updateContentDocument($chunk);
  }
  else {

    // Create a new Lingotek Document.
    $result = $api
      ->addContentDocument($chunk, TRUE);
  }

  // WTD: This section has not been updated to accommodate results from config-chunk documents,
  // as I couldn't find where the references to $context were being used after making this call
  if ($result) {
    $context['results']['uploads'] = isset($context['results']['uploads']) && is_numeric($context['results']['uploads']) ? $context['results']['uploads'] + 1 : 1;
    if (!isset($context['results']['uploaded_cids']) || !is_array($context['results']['uploaded_cids'])) {
      $context['results']['uploaded_cids'] = array();
    }
    $context['results']['uploaded_cids'][] = $cid;
  }
  else {
    $context['results']['upload_fails'] = isset($context['results']['upload_fails']) && is_numeric($context['results']['upload_fails']) ? $context['results']['upload_fails'] + 1 : 1;
    if (!isset($context['results']['upload_fail_cids']) || !is_array($context['results']['upload_fail_cids'])) {
      $context['results']['upload_fail_cids'] = array();
    }
    $context['results']['upload_fail_cids'][] = $cid;
  }
}