You are here

function lingotek_get_trans_obj in Lingotek Translation 7.5

Same name and namespace in other branches
  1. 7.7 lingotek.sync.inc \lingotek_get_trans_obj()
  2. 7.6 lingotek.sync.inc \lingotek_get_trans_obj()
1 call to lingotek_get_trans_obj()
lingotek_notifications in ./lingotek.sync.inc
Registers the site translation notfication callback.

File

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

Code

function lingotek_get_trans_obj($document_id, $document_idx) {

  // Adding a delay in the update.  Without the delay all the different language updates hit at once, causing node lock issues as multiple languages try to update the same node at once.
  $min = 0;
  $max = 3;
  $sleep = rand($min, $max);
  sleep($sleep);
  $trans_obj = NULL;

  // try 3 times if by chance we don't find the document in the database yet..
  $attempts = 0;
  while ($attempts < 3) {
    list($id, $type) = LingotekSync::getEntityIdFromDocId($document_id);
    if (!$id) {

      // check for the old style document_id
      list($id, $type) = LingotekSync::getEntityIdFromDocId($document_idx);
      if ($id) {
        $document_id = $document_idx;
      }
    }
    if ($id) {
      $entity = lingotek_entity_load_single($type, $id);
      $trans_obj = LingotekEntity::load($entity, $type);
      break;
    }
    if ($trans_obj = LingotekConfigChunk::loadByLingotekDocumentId($document_id)) {
      break;
    }
    LingotekLog::info('Did not find doc ID @doc_id yet on attempt #@attempt, retrying...', array(
      '@attempt' => $attempts,
      '@doc_id' => $document_id,
    ));
    sleep(2);
    $attempts++;
  }
  if (!$trans_obj) {
    LingotekLog::error('Did not find doc ID @doc_id after all attempts.  Giving up.', array(
      '@doc_id' => $document_id,
    ));
  }
  return $trans_obj;
}