You are here

protected function SqlImport::importExpirable in MongoDB 8.2

Import an expirable database KV store.

This function needs to access the table-level information for the expirable database KV store because the KeyValueExpirableStore[Interface] does not provide access to the "expire" information.

Parameters

\Drupal\Core\Database\StatementInterface $cursor: A cursor enumerating collections in a database KV store.

string $tableName: The name of the database collection table.

1 call to SqlImport::importExpirable()
SqlImport::import in modules/mongodb_storage/src/Install/SqlImport.php
The command implementation for most-ikv: import the DB KV to MongoDB.

File

modules/mongodb_storage/src/Install/SqlImport.php, line 152

Class

SqlImport
Service providing the import of the SQL-based KV storage to MongoDB.

Namespace

Drupal\mongodb_storage\Install

Code

protected function importExpirable(StatementInterface $cursor, string $tableName) {
  $columns = [
    'name',
    'value',
    'expire',
  ];
  foreach ($cursor as $row) {
    $collection = $row->collection;
    $valueCursor = $this->database
      ->select($tableName, 'kve')
      ->fields('kve', $columns)
      ->condition('kve.collection', $collection)
      ->execute();

    /** @var \Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface $mgStore */
    $mgStore = $this->expirableMoFactory
      ->get($collection, FALSE);
    $mgStore
      ->deleteAll();
    foreach ($valueCursor as $valueRow) {
      $key = $valueRow->name;
      $value = unserialize($valueRow->value);
      $now = $this->time
        ->getCurrentTime();
      $expire = $valueRow->expire;
      $mgStore
        ->setWithExpire($key, $value, $expire - $now);
    }
  }
}