You are here

protected function LingotekContentTranslationService::getClosestRevisionToTimestamp in Lingotek Translation 8.2

Same name and namespace in other branches
  1. 8 src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::getClosestRevisionToTimestamp()
  2. 4.0.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::getClosestRevisionToTimestamp()
  3. 3.0.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::getClosestRevisionToTimestamp()
  4. 3.1.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::getClosestRevisionToTimestamp()
  5. 3.2.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::getClosestRevisionToTimestamp()
  6. 3.3.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::getClosestRevisionToTimestamp()
  7. 3.4.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::getClosestRevisionToTimestamp()
  8. 3.5.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::getClosestRevisionToTimestamp()
  9. 3.6.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::getClosestRevisionToTimestamp()
  10. 3.7.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::getClosestRevisionToTimestamp()
  11. 3.8.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::getClosestRevisionToTimestamp()
1 call to LingotekContentTranslationService::getClosestRevisionToTimestamp()
LingotekContentTranslationService::loadUploadedRevision in src/LingotekContentTranslationService.php
Loads the correct revision is loaded from the database, bypassing caches.

File

src/LingotekContentTranslationService.php, line 1264

Class

LingotekContentTranslationService
Service for managing Lingotek content translations.

Namespace

Drupal\lingotek

Code

protected function getClosestRevisionToTimestamp(ContentEntityInterface &$entity, $timestamp) {
  $entity_id = $entity
    ->id();
  $query = \Drupal::database()
    ->select($entity
    ->getEntityType()
    ->getRevisionDataTable(), 'nfr');
  $query
    ->fields('nfr', [
    $entity
      ->getEntityType()
      ->getKey('revision'),
  ]);
  $query
    ->addJoin('INNER', $entity
    ->getEntityType()
    ->getRevisionTable(), 'nr', 'nfr.vid = nr.vid and nfr.nid = nr.nid and nfr.langcode = nr.langcode');
  $query
    ->condition('nfr.' . $entity
    ->getEntityType()
    ->getKey('id'), $entity_id);
  $query
    ->condition('nfr.' . $entity
    ->getEntityType()
    ->getKey('langcode'), $entity
    ->language()
    ->getId());
  $query
    ->condition('nr.revision_timestamp', $timestamp, '<');
  $query
    ->orderBy('nfr.changed', 'DESC');
  $query
    ->range(0, 1);
  $value = $query
    ->execute();
  $vids = $value
    ->fetchAssoc();
  return $vids !== FALSE && count($vids) === 1 ? $vids['vid'] : NULL;
}