You are here

public function LingotekContentTranslationService::checkSourceStatus in Lingotek Translation 3.7.x

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

Checks the source is uploaded correctly.

Parameters

\Drupal\Core\Entity\ContentEntityInterface &$entity: The entity which status we want to check.

Return value

bool True if the entity is uploaded successfully.

Overrides LingotekContentTranslationServiceInterface::checkSourceStatus

File

src/LingotekContentTranslationService.php, line 136

Class

LingotekContentTranslationService
Service for managing Lingotek content translations.

Namespace

Drupal\lingotek

Code

public function checkSourceStatus(ContentEntityInterface &$entity) {
  $profile = $this->lingotekConfiguration
    ->getEntityProfile($entity);
  if ($profile
    ->id() === Lingotek::PROFILE_DISABLED || $this
    ->getSourceStatus($entity) === Lingotek::STATUS_CANCELLED) {
    return FALSE;
  }
  $document_id = $this
    ->getDocumentId($entity);
  if ($document_id) {

    // Document has successfully imported.
    try {
      $status = $this->lingotek
        ->getDocumentStatus($document_id);
    } catch (LingotekDocumentLockedException $exception) {
      $this
        ->setDocumentId($entity, $exception
        ->getNewDocumentId());
      throw $exception;
    } catch (LingotekDocumentNotFoundException $exception) {
      if ($this
        ->checkUploadProcessId($entity)) {

        // If the document was not found and the process completed means that
        // the document might have been deleted afterwards.
        // We check for timeout to set an error if needed.
        if (!$this
          ->checkForTimeout($entity)) {
          $this
            ->setDocumentId($entity, NULL);
          $this
            ->deleteMetadata($entity);
          throw $exception;
        }
      }
      else {

        // The document is not ready yet, but the check operation is still in
        // progress.
        $this
          ->checkForTimeout($entity);
        return FALSE;
      }
    } catch (LingotekDocumentArchivedException $exception) {
      $this
        ->setDocumentId($entity, NULL);
      $this
        ->deleteMetadata($entity);
      throw $exception;
    } catch (LingotekPaymentRequiredException $exception) {
      throw $exception;
    } catch (LingotekApiException $exception) {
      throw $exception;
    }
    if ($status) {
      $this
        ->setSourceStatus($entity, Lingotek::STATUS_CURRENT);
      return TRUE;
    }
    else {
      if (!$this
        ->checkUploadProcessId($entity)) {

        // I'm not sure if this is relevant anymore, as the timeout will
        // probably trigger a 404. We leave it just in case.
        $this
          ->checkForTimeout($entity);
        return FALSE;
      }
      else {

        // The document is not ready yet, but the check operation succeeded.
        return FALSE;
      }
    }
  }
  if ($this
    ->getSourceStatus($entity) == Lingotek::STATUS_DISABLED) {
    $this
      ->setTargetStatuses($entity, Lingotek::STATUS_DISABLED);
  }
  return FALSE;
}