You are here

public function LingotekContentTranslationService::checkSourceStatus in Lingotek Translation 8

Same name and namespace in other branches
  1. 8.2 src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::checkSourceStatus()
  2. 4.0.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::checkSourceStatus()
  3. 3.0.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::checkSourceStatus()
  4. 3.1.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

ContentEntityInterface &$entity: The entity which status we want to check.

Return value

boolean True if the entity is uploaded successfully.

Overrides LingotekContentTranslationServiceInterface::checkSourceStatus

File

src/LingotekContentTranslationService.php, line 102
Contains \Drupal\lingotek\LingotekContentTranslationService.

Class

LingotekContentTranslationService
Service for managing Lingotek content translations.

Namespace

Drupal\lingotek

Code

public function checkSourceStatus(ContentEntityInterface &$entity) {
  $document_id = $this
    ->getDocumentId($entity);

  // We set a max time of 1 hour for the import (in seconds)
  $MAX_IMPORT_TIME = 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()
        ->isSubclassOf(EntityChangedInterface::class)) {
        $last_uploaded_time = $entity
          ->getChangedTime();

        // If document has not successfully imported after MAX_IMPORT_TIME then
        // move to ERROR state.
        if (REQUEST_TIME - $last_uploaded_time > $MAX_IMPORT_TIME) {
          $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;
    }
  }
  return FALSE;
}