You are here

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

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

Resends a document to the translation service.

Parameters

$mapper_id: The entity 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\LingotekApiException

\Drupal\lingotek\Exception\LingotekDocumentArchivedException

\Drupal\lingotek\Exception\LingotekDocumentLockedException

Overrides LingotekConfigTranslationServiceInterface::updateConfig

1 call to LingotekConfigTranslationService::updateConfig()
LingotekConfigTranslationService::uploadConfig in src/LingotekConfigTranslationService.php
Uploads a document to the Lingotek service.

File

src/LingotekConfigTranslationService.php, line 1490

Class

LingotekConfigTranslationService
Service for managing Lingotek configuration translations.

Namespace

Drupal\lingotek

Code

public function updateConfig($mapper_id, $job_id = NULL) {
  $mapper = $this->mappers[$mapper_id];
  $profile = $this->lingotekConfiguration
    ->getConfigProfile($mapper_id, FALSE);
  if ($profile !== NULL && $profile
    ->id() === Lingotek::PROFILE_DISABLED || $this
    ->getConfigSourceStatus($mapper) === Lingotek::STATUS_CANCELLED) {
    return FALSE;
  }

  // Get the provide providing a default.
  $profile = $this->lingotekConfiguration
    ->getConfigProfile($mapper_id);

  // If job id was not set in the form, it may be already assigned.
  if ($job_id === NULL) {
    $job_id = $this
      ->getConfigJobId($mapper) ?: NULL;
  }
  $source_data = json_encode($this
    ->getConfigSourceData($mapper));
  $document_id = $this
    ->getConfigDocumentId($mapper);
  $extended_name = $mapper_id . ' (config): ' . $mapper
    ->getTitle();
  $profile_preference = $profile
    ->getAppendContentTypeToTitle();
  $global_preference = $this->lingotekConfiguration
    ->getPreference('append_type_to_title');
  switch ($profile_preference) {
    case 'yes':
      $document_name = $extended_name;
      break;
    case 'no':
      $document_name = (string) $mapper
        ->getTitle();
      break;
    case 'global_setting':
      $document_name = $global_preference ? $extended_name : (string) $mapper
        ->getTitle();
      break;
    default:
      $document_name = $extended_name;
  }
  $newDocumentID = NULL;
  try {
    $newDocumentID = $this->lingotek
      ->updateDocument($document_id, $source_data, NULL, $document_name, $profile, $job_id, $this
      ->getConfigSourceLocale($mapper));
  } catch (LingotekDocumentLockedException $exception) {
    $this
      ->setConfigDocumentId($mapper, $exception
      ->getNewDocumentId());

    // TODO: It shouldn't be needed here, EDITED status should already be set.
    $this
      ->setConfigSourceStatus($mapper, Lingotek::STATUS_EDITED);
    throw $exception;
  } catch (LingotekDocumentArchivedException $exception) {
    $this
      ->setConfigSourceStatus($mapper, NULL);
    $this
      ->deleteConfigMetadata($mapper
      ->getPluginId());
    throw $exception;
  } catch (LingotekPaymentRequiredException $exception) {
    $this
      ->setConfigSourceStatus($mapper, Lingotek::STATUS_ERROR);
    throw $exception;
  } catch (LingotekApiException $exception) {
    $this
      ->setConfigSourceStatus($mapper, Lingotek::STATUS_ERROR);
    throw $exception;
  }
  if ($newDocumentID) {
    if (is_string($newDocumentID)) {
      $this
        ->setConfigDocumentId($mapper, $newDocumentID);
    }
    $this
      ->setConfigSourceStatus($mapper, Lingotek::STATUS_IMPORTING);
    $this
      ->setConfigTargetStatuses($mapper, Lingotek::STATUS_PENDING);
    $this
      ->setConfigJobId($mapper, $job_id);
    $this
      ->setConfigLastUpdated($mapper, \Drupal::time()
      ->getRequestTime());
    return $document_id;
  }
  if ($this
    ->getConfigSourceStatus($mapper) == Lingotek::STATUS_DISABLED) {
    $this
      ->setConfigTargetStatuses($mapper, Lingotek::STATUS_DISABLED);
  }
  return FALSE;
}