You are here

public function LingotekFake::updateDocument in Lingotek Translation 3.7.x

Same name and namespace in other branches
  1. 8 tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::updateDocument()
  2. 8.2 tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::updateDocument()
  3. 4.0.x tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::updateDocument()
  4. 3.0.x tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::updateDocument()
  5. 3.1.x tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::updateDocument()
  6. 3.2.x tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::updateDocument()
  7. 3.3.x tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::updateDocument()
  8. 3.4.x tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::updateDocument()
  9. 3.5.x tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::updateDocument()
  10. 3.6.x tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::updateDocument()
  11. 3.8.x tests/modules/lingotek_test/src/LingotekFake.php \Drupal\lingotek_test\LingotekFake::updateDocument()

Updates a document in the Lingotek service.

Parameters

string $doc_id: The document id to update.

string|array $content: The content of the document. It can be a json string or an array that will be json encoded.

string $url: (optional) The document url in the site if any. This allows support for in-context review.

string $title: (optional) The title of the document as it will be seen in the TMS.

\Drupal\lingotek\LingotekProfileInterface $profile: (optional) The profile being used.

string $job_id: (optional) The job ID that will be associated.

string $locale: (optional) The Lingotek locale.

string &$process_id: (optional) It will be filled with the process id on the TMS.

Return value

bool|string TRUE if the document was successfully updated. FALSE if not (v5.1). New document ID if the document was successfully updated. FALSE if not (v5.2).

Throws

\Drupal\lingotek\Exception\LingotekPaymentRequiredException

\Drupal\lingotek\Exception\LingotekDocumentArchivedException

\Drupal\lingotek\Exception\LingotekDocumentLockedException

\Drupal\lingotek\Exception\LingotekDocumentNotFoundException

\Drupal\lingotek\Exception\LingotekApiException

Overrides LingotekInterface::updateDocument

1 method overrides LingotekFake::updateDocument()
LingotekFakeBC::updateDocument in tests/modules/lingotek_test/src/LingotekFakeBC.php
Updates a document in the Lingotek service.

File

tests/modules/lingotek_test/src/LingotekFake.php, line 184

Class

LingotekFake

Namespace

Drupal\lingotek_test

Code

public function updateDocument($doc_id, $content, $url = NULL, $title = NULL, LingotekProfileInterface $profile = NULL, $job_id = NULL, $locale = NULL, &$process_id = NULL) {
  $newId = TRUE;
  if (\Drupal::state()
    ->get('lingotek.must_error_in_upload', FALSE)) {
    \Drupal::state()
      ->set('lingotek.must_error_in_upload', FALSE);
    throw new LingotekApiException('Error was forced.');
  }
  if (\Drupal::state()
    ->get('lingotek.must_document_not_found_error_in_update', FALSE)) {
    throw new LingotekDocumentNotFoundException($doc_id . ' not found. Error was forced.');
  }
  if (\Drupal::state()
    ->get('lingotek.must_payment_required_error_in_update', FALSE)) {
    \Drupal::state()
      ->set('lingotek.must_payment_required_error_in_update', FALSE);
    throw new LingotekPaymentRequiredException('Error was forced.');
  }
  if (\Drupal::state()
    ->get('lingotek.must_document_archived_error_in_update', FALSE)) {
    \Drupal::state()
      ->set('lingotek.must_document_archived_error_in_update', FALSE);
    throw new LingotekDocumentArchivedException($doc_id, 'Error was forced.');
  }
  if (\Drupal::state()
    ->get('lingotek.must_document_locked_error_in_update', FALSE)) {
    \Drupal::state()
      ->set('lingotek.must_document_locked_error_in_update', FALSE);
    throw new LingotekDocumentLockedException($doc_id, 'new-doc-id', 'Error was forced.');
  }
  if (is_array($content)) {
    $content = json_encode($content);
  }
  if ($content === NULL) {
    $newId = FALSE;
  }
  \Drupal::state()
    ->set('lingotek.uploaded_content', $content);
  \Drupal::state()
    ->set('lingotek.uploaded_content_url', $url);
  \Drupal::state()
    ->set('lingotek.uploaded_title', $title);
  \Drupal::state()
    ->set('lingotek.uploaded_job_id', $job_id);
  if ($newId) {
    $last_doc_id = \Drupal::state()
      ->get('lingotek.last_used_id', 0);
    $new_doc_id = 'dummy-document-hash-id';
    if ($last_doc_id > 0) {
      $new_doc_id .= '-' . $last_doc_id;
    }
    ++$last_doc_id;
    \Drupal::state()
      ->set('lingotek.last_used_id', $last_doc_id);
  }
  else {
    $new_doc_id = $doc_id;
  }
  $requested_locales = \Drupal::state()
    ->get('lingotek.requested_locales', []);
  if (isset($requested_locales[$doc_id])) {
    $new_requested_locales = [];
    foreach ($requested_locales as $id => $requested_locale) {
      if ($doc_id === $id) {
        $new_requested_locales[$new_doc_id] = $requested_locale;
      }
      else {
        $new_requested_locales[$new_doc_id] = $requested_locale;
      }
    }
    $requested_locales = $new_requested_locales;
  }
  \Drupal::state()
    ->set('lingotek.requested_locales', $requested_locales);

  // Save the timestamp of the upload.
  $timestamps = \Drupal::state()
    ->get('lingotek.upload_timestamps', []);
  $timestamps[$doc_id] = \Drupal::time()
    ->getRequestTime();
  \Drupal::state()
    ->set('lingotek.upload_timestamps', $timestamps);

  // Set a process id, same as doc.
  $process_id = $new_doc_id;

  // Our document is always imported correctly.
  return $new_doc_id;
}