You are here

function check_entity_progress_for_download in Lingotek Translation 7.7

1 call to check_entity_progress_for_download()
lingotek_get_and_update_target_progress in ./lingotek.sync.inc
Updates the 'target_sync_status_[lang-code]' field for every target in the lingotek table with the overall progress returned by TMS

File

./lingotek.sync.inc, line 459
Sync and management

Code

function check_entity_progress_for_download($update_context, $api) {
  $document_id = $update_context['entity']->lingotek['document_id'];
  $doc_failed = update_pending_sources($document_id, $api);
  if (!empty($doc_failed)) {
    return;
  }
  $project_id = variable_get('lingotek_project', NULL);
  $id = lingotek_entity_extract_ids($update_context['entity_type'], $update_context['entity']);
  if (empty($document_id) || empty($project_id) || empty($id)) {
    return LingotekLog::error("Issue updating target process on line @line in file @file", array(
      '@line' => __LINE__,
      '@file' => __FILE__,
    ));
  }
  $progress_report = $api
    ->getProgressReport($project_id, array(
    $document_id,
  ));
  $protected_statuses = array(
    LingotekSync::STATUS_UNTRACKED,
    LingotekSync::STATUS_CURRENT,
    LingotekSync::STATUS_INTERIM,
  );
  if (isset($progress_report) && isset($progress_report->byTargetLocale) && isset($progress_report->workflowCompletedByDocumentIdAndTargetLocale) && $progress_report->results == "success") {
    foreach ($progress_report->byTargetLocale as $locale => $percent_complete) {
      if (in_array(LingotekSync::getTargetStatus($document_id, $locale), $protected_statuses)) {
        continue;
      }
      elseif (!empty($progress_report->workflowCompletedByDocumentIdAndTargetLocale->{$document_id}->{$locale})) {

        // There was an issue where the progress report was saying that the target was incomplete when it WAS complete
        lingotek_keystore($update_context['entity_type'], $id[0], 'target_sync_status_' . $locale, LingotekSync::STATUS_READY);
        continue;
      }
      if ($percent_complete == 0) {
        lingotek_keystore($update_context['entity_type'], $id[0], 'target_sync_status_' . $locale, LingotekSync::STATUS_PENDING);
      }
      elseif ($percent_complete > 0 && $percent_complete < 100) {
        lingotek_keystore($update_context['entity_type'], $id[0], 'target_sync_status_' . $locale, LingotekSync::STATUS_READY_INTERIM);
      }
      elseif ($percent_complete == 100) {
        lingotek_keystore($update_context['entity_type'], $id[0], 'target_sync_status_' . $locale, LingotekSync::STATUS_READY);
      }
      else {
        LingotekLog::error("Unknown status for locale @locale on nodeID #@current_nid.", array(
          '@locale' => $locale,
          '@current_nid' => $id[0],
        ));
      }
    }
  }
}