You are here

public function LingotekConfigTranslationService::setConfigJobId in Lingotek Translation 3.4.x

Same name and namespace in other branches
  1. 8.2 src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::setConfigJobId()
  2. 4.0.x src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::setConfigJobId()
  3. 3.0.x src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::setConfigJobId()
  4. 3.1.x src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::setConfigJobId()
  5. 3.2.x src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::setConfigJobId()
  6. 3.3.x src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::setConfigJobId()
  7. 3.5.x src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::setConfigJobId()
  8. 3.6.x src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::setConfigJobId()
  9. 3.7.x src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::setConfigJobId()
  10. 3.8.x src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::setConfigJobId()

Sets the job ID of a given mapper.

Parameters

\Drupal\config_translation\ConfigNamesMapper $mapper: The mapper we want to save a job id for.

$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

\Drupal\Core\Entity\ContentEntityInterface Returns the mapper which job ID is saved.

Throws

\Drupal\lingotek\Exception\LingotekPaymentRequiredException

\Drupal\lingotek\Exception\LingotekDocumentArchivedException

\Drupal\lingotek\Exception\LingotekDocumentLockedException

\Drupal\lingotek\Exception\LingotekApiException

Overrides LingotekConfigTranslationServiceInterface::setConfigJobId

2 calls to LingotekConfigTranslationService::setConfigJobId()
LingotekConfigTranslationService::updateConfig in src/LingotekConfigTranslationService.php
Resends a document to the translation service.
LingotekConfigTranslationService::uploadConfig in src/LingotekConfigTranslationService.php
Uploads a document to the Lingotek service.

File

src/LingotekConfigTranslationService.php, line 1633

Class

LingotekConfigTranslationService
Service for managing Lingotek configuration translations.

Namespace

Drupal\lingotek

Code

public function setConfigJobId(ConfigNamesMapper $mapper, $job_id, $update_tms = FALSE) {
  $newDocumentID = FALSE;
  if ($update_tms && ($document_id = $this
    ->getConfigDocumentId($mapper))) {
    try {
      $newDocumentID = $this->lingotek
        ->updateDocument($document_id, NULL, NULL, NULL, NULL, $job_id, $this
        ->getConfigSourceLocale($mapper));
    } catch (LingotekDocumentLockedException $exception) {
      $this
        ->setConfigDocumentId($mapper, $exception
        ->getNewDocumentId());
      throw $exception;
    } catch (LingotekDocumentArchivedException $exception) {
      $old_job_id = $this
        ->getConfigJobId($mapper);
      $this
        ->setConfigDocumentId($mapper, NULL);
      $this
        ->deleteConfigMetadata($mapper
        ->getPluginId());
      $config_names = $mapper
        ->getConfigNames();
      foreach ($config_names as $config_name) {
        $metadata = LingotekConfigMetadata::loadByConfigName($config_name);
        $metadata
          ->setJobId($old_job_id);
        $metadata
          ->save();
      }
      throw $exception;
    } catch (LingotekPaymentRequiredException $exception) {
      throw $exception;
    } catch (LingotekApiException $exception) {
      throw $exception;
    }
  }
  $config_names = $mapper
    ->getConfigNames();
  foreach ($config_names as $config_name) {
    $metadata = LingotekConfigMetadata::loadByConfigName($config_name);
    if (is_string($newDocumentID)) {
      $metadata
        ->setDocumentId($newDocumentID);
    }
    $metadata
      ->setJobId($job_id);
    $metadata
      ->save();
  }
  return $mapper;
}