You are here

public function LingotekInterfaceTranslationService::updateDocument in Lingotek Translation 3.6.x

Same name and namespace in other branches
  1. 4.0.x src/LingotekInterfaceTranslationService.php \Drupal\lingotek\LingotekInterfaceTranslationService::updateDocument()
  2. 3.2.x src/LingotekInterfaceTranslationService.php \Drupal\lingotek\LingotekInterfaceTranslationService::updateDocument()
  3. 3.3.x src/LingotekInterfaceTranslationService.php \Drupal\lingotek\LingotekInterfaceTranslationService::updateDocument()
  4. 3.4.x src/LingotekInterfaceTranslationService.php \Drupal\lingotek\LingotekInterfaceTranslationService::updateDocument()
  5. 3.5.x src/LingotekInterfaceTranslationService.php \Drupal\lingotek\LingotekInterfaceTranslationService::updateDocument()
  6. 3.7.x src/LingotekInterfaceTranslationService.php \Drupal\lingotek\LingotekInterfaceTranslationService::updateDocument()
  7. 3.8.x src/LingotekInterfaceTranslationService.php \Drupal\lingotek\LingotekInterfaceTranslationService::updateDocument()

Resends a document to the translation service.

Parameters

string $component: The component being updated.

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

Return value

bool TRUE if the document was updated successfully, FALSE if not.

Throws

\Drupal\lingotek\Exception\LingotekPaymentRequiredException

\Drupal\lingotek\Exception\LingotekDocumentArchivedException

\Drupal\lingotek\Exception\LingotekDocumentLockedException

\Drupal\lingotek\Exception\LingotekApiException

Overrides LingotekInterfaceTranslationServiceInterface::updateDocument

1 call to LingotekInterfaceTranslationService::updateDocument()
LingotekInterfaceTranslationService::uploadDocument in src/LingotekInterfaceTranslationService.php
Uploads a document to the Lingotek service.

File

src/LingotekInterfaceTranslationService.php, line 667

Class

LingotekInterfaceTranslationService
Service for managing Lingotek interface translations.

Namespace

Drupal\lingotek

Code

public function updateDocument($component, $job_id = NULL) {

  // If job id was not set in the form, it may be already assigned.
  if ($job_id === NULL) {
    $job_id = $this
      ->getJobId($component) ?: NULL;
  }
  $source_data = $this
    ->getSourceData($component);
  $document_id = $this
    ->getDocumentId($component);
  $document_name = 'Interface translation: ' . $component;

  // Allow other modules to alter the data before is uploaded.
  \Drupal::moduleHandler()
    ->invokeAll('lingotek_interface_translation_document_upload', [
    &$source_data,
    &$component,
  ]);
  try {
    $newDocumentID = $this->lingotek
      ->updateDocument($document_id, $source_data, NULL, $document_name, NULL, $job_id, $this
      ->getSourceLocale($component));
  } catch (LingotekDocumentLockedException $exception) {
    $this
      ->setDocumentId($component, $exception
      ->getNewDocumentId());
    throw $exception;
  } catch (LingotekDocumentArchivedException $exception) {
    $this
      ->setDocumentId($component, NULL);
    $this
      ->deleteMetadata($component);
    throw $exception;
  } catch (LingotekPaymentRequiredException $exception) {
    $this
      ->setSourceStatus($component, Lingotek::STATUS_ERROR);
    throw $exception;
  } catch (LingotekApiException $exception) {
    $this
      ->setSourceStatus($component, Lingotek::STATUS_ERROR);
    throw $exception;
  }
  if ($newDocumentID) {
    if (is_string($newDocumentID)) {
      $document_id = $newDocumentID;
      $this
        ->setDocumentId($component, $newDocumentID);
    }
    $this
      ->setSourceStatus($component, Lingotek::STATUS_IMPORTING);
    $this
      ->setTargetStatuses($component, Lingotek::STATUS_PENDING);
    $this
      ->setJobId($component, $job_id);
    $this
      ->setLastUpdated($component, \Drupal::time()
      ->getRequestTime());
    return $document_id;
  }
  return FALSE;
}