function CurrentImportStorage::get

Get current import information for a given project and language.

Parameters

string $project: Project to get.

string $langcode: Langcode to get.

Return value

\Drupal\locale\CurrentImport|null A CurrentImport object if one exists for this project/language.

File

core/modules/locale/src/CurrentImportStorage.php, line 47

Class

CurrentImportStorage
Provides the locale current import state service.

Namespace

Drupal\locale

Code

public function get(string $project, string $langcode) : ?CurrentImport {
  $currentImport = NULL;
  $cid = $this->getCacheId($project, $langcode);
  if ($cached = $this->memoryCache
    ->get($cid)) {
    $currentImport = $cached->data;
  }
  else {
    $result = $this->database
      ->select('locale_file')
      ->fields('locale_file', [
      'project',
      'langcode',
      'version',
      'timestamp',
      'hash',
      'last_checked',
    ])
      ->condition('project', $project)
      ->condition('langcode', $langcode)
      ->execute()
      ->fetch(FetchAs::Associative);
    if ($result) {
      $currentImport = CurrentImport::createFromArray($result);
      $this->memoryCache
        ->set($this->getCacheId($currentImport->project, $currentImport->langcode), $currentImport, Cache::PERMANENT, [
        self::LOCALE_CURRENT_IMPORT_CACHE_TAG,
      ]);
    }
  }
  return $currentImport;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.