You are here

public function LingotekContentTranslationService::checkSourceStatus in Lingotek Translation 3.1.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.2.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::checkSourceStatus()
  6. 3.3.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::checkSourceStatus()
  7. 3.4.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::checkSourceStatus()
  8. 3.5.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::checkSourceStatus()
  9. 3.6.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::checkSourceStatus()
  10. 3.7.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 127

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);

  // We set a max time of 1 hour for the import (in seconds)
  $maxImportTime = 3600;
  $source_status = $this
    ->getSourceStatus($entity);
  if ($document_id) {

    // Document has successfully imported.
    if ($this->lingotek
      ->getDocumentStatus($document_id)) {
      $this
        ->setSourceStatus($entity, Lingotek::STATUS_CURRENT);
      return TRUE;
    }
    else {

      // TODO: change to actual last_uploaded timestamp rather than surrogate.
      if ($entity
        ->getEntityType()
        ->entityClassImplements(EntityChangedInterface::class)) {
        $last_uploaded_time = $entity
          ->getChangedTime();

        // If document has not successfully imported after MAX_IMPORT_TIME
        // then move to ERROR state.
        if (\Drupal::time()
          ->getRequestTime() - $last_uploaded_time > $maxImportTime) {
          $this
            ->setSourceStatus($entity, Lingotek::STATUS_ERROR);
        }
        else {

          // Document still may be importing and the MAX import time didn't
          // complete yet, so we do nothing.
        }
      }
      return FALSE;
    }
  }
  if ($this
    ->getSourceStatus($entity) == Lingotek::STATUS_DISABLED) {
    $this
      ->setTargetStatuses($entity, Lingotek::STATUS_DISABLED);
  }
  return FALSE;
}