You are here

public function DatabaseStorageList::pushMultiple in Key-value Extensions 8

Parameters

array $values:

Return value

null

Overrides KeyValueStoreListInterface::pushMultiple

1 call to DatabaseStorageList::pushMultiple()
DatabaseStorageList::push in src/KeyValueStore/DatabaseStorageList.php

File

src/KeyValueStore/DatabaseStorageList.php, line 31

Class

DatabaseStorageList

Namespace

Drupal\key_value\KeyValueStore

Code

public function pushMultiple(array $values) {

  // @todo Find out if there's a way to do this query/sub-query combination
  // in one atomic operation.
  foreach ($values as $value) {
    $sub_query = $this->connection
      ->select($this->table, 't')
      ->condition('t.collection', $this->collection);
    $sub_query
      ->addExpression(':collection', 'collection', [
      ':collection' => $this->collection,
    ]);
    $sub_query
      ->addExpression('IFNULL(MAX(t.name) + 1, 0)', 'name');
    $sub_query
      ->addExpression(':value', 'value', [
      ':value' => $this->serializer
        ->encode($value),
    ]);
    $this->connection
      ->insert($this->table)
      ->from($sub_query)
      ->execute();
  }
}