You are here

public function LingotekInterfaceTranslationService::setJobId in Lingotek Translation 3.4.x

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

Sets the job ID of a given component.

Parameters

string $component: The component we want to save a job id for.

string $job_id: The job ID being saved.

bool $update_tms: (Optional) Flag indicating if the change should be communicated to the TMS. False by default.

Return value

string Returns the component which job ID is saved.

Throws

\Drupal\lingotek\Exception\LingotekPaymentRequiredException

\Drupal\lingotek\Exception\LingotekDocumentArchivedException

\Drupal\lingotek\Exception\LingotekDocumentLockedException

\Drupal\lingotek\Exception\LingotekApiException

Overrides LingotekInterfaceTranslationServiceInterface::setJobId

2 calls to LingotekInterfaceTranslationService::setJobId()
LingotekInterfaceTranslationService::updateDocument in src/LingotekInterfaceTranslationService.php
Resends a document to the translation service.
LingotekInterfaceTranslationService::uploadDocument in src/LingotekInterfaceTranslationService.php
Uploads a document to the Lingotek service.

File

src/LingotekInterfaceTranslationService.php, line 971

Class

LingotekInterfaceTranslationService
Service for managing Lingotek interface translations.

Namespace

Drupal\lingotek

Code

public function setJobId($component, $job_id, $update_tms = FALSE) {
  $metadata = $this
    ->getMetadata($component);
  $newDocumentID = FALSE;
  if ($update_tms && ($document_id = $this
    ->getDocumentId($component))) {
    try {
      $newDocumentID = $this->lingotek
        ->updateDocument($document_id, NULL, NULL, NULL, NULL, $job_id);
    } catch (LingotekDocumentLockedException $exception) {
      $this
        ->setDocumentId($component, $exception
        ->getNewDocumentId());
      throw $exception;
    } catch (LingotekDocumentArchivedException $exception) {
      $old_job_id = $this
        ->getJobId($component);
      $this
        ->deleteMetadata($component);
      $metadata = $this
        ->getMetadata($component);
      $metadata['job_id'] = $old_job_id;
      $this
        ->saveMetadata($component, $metadata);
      throw $exception;
    } catch (LingotekPaymentRequiredException $exception) {
      throw $exception;
    } catch (LingotekApiException $exception) {
      throw $exception;
    }
  }
  if (is_string($newDocumentID)) {
    $metadata['document_id'] = $newDocumentID;
  }
  $metadata['job_id'] = $job_id;
  $this
    ->saveMetadata($component, $metadata);
  return $component;
}