diff --git a/core/lib/Drupal/Core/KeyValueStore/KeyValueMemoryFactory.php b/core/lib/Drupal/Core/KeyValueStore/KeyValueMemoryFactory.php index e2942c2ae60..a964042c0f9 100644 --- a/core/lib/Drupal/Core/KeyValueStore/KeyValueMemoryFactory.php +++ b/core/lib/Drupal/Core/KeyValueStore/KeyValueMemoryFactory.php @@ -8,7 +8,7 @@ namespace Drupal\Core\KeyValueStore; /** - * Defines the key/value store factory for the database backend. + * Defines the key/value store factory for the memory backend. */ class KeyValueMemoryFactory implements KeyValueFactoryInterface { diff --git a/core/modules/user/src/TempStoreFactory.php b/core/modules/user/src/TempStoreFactory.php index 70a92898e9b..bd08146effd 100644 --- a/core/modules/user/src/TempStoreFactory.php +++ b/core/modules/user/src/TempStoreFactory.php @@ -8,8 +8,7 @@ namespace Drupal\user; use Drupal\Component\Serialization\SerializationInterface; -use Drupal\Core\Database\Connection; -use Drupal\Core\KeyValueStore\DatabaseStorageExpirable; +use Drupal\Core\KeyValueStore\KeyValueExpirableFactoryInterface; use Drupal\Core\Lock\LockBackendInterface; /** @@ -18,18 +17,11 @@ use Drupal\Core\Lock\LockBackendInterface; class TempStoreFactory { /** - * The serialization class to use. + * The storage factory creating the backend to store the data. * - * @var \Drupal\Component\Serialization\SerializationInterface + * @var \Drupal\Core\KeyValueStore\KeyValueExpirableFactoryInterface */ - protected $serializer; - - /** - * The connection object used for this data. - * - * @var \Drupal\Core\Database\Connection $connection - */ - protected $connection; + protected $storageFactory; /** * The lock object used for this data. @@ -48,8 +40,6 @@ class TempStoreFactory { /** * Constructs a Drupal\user\TempStoreFactory object. * - * @param \Drupal\Component\Serialization\SerializationInterface $serializer - * The serialization class to use. * @param \Drupal\Core\Database\Connection $connection * The connection object used for this data. * @param \Drupal\Core\Lock\LockBackendInterface $lockBackend @@ -57,9 +47,8 @@ class TempStoreFactory { * @param int $expire * The time to live for items, in seconds. */ - function __construct(SerializationInterface $serializer, Connection $connection, LockBackendInterface $lockBackend, $expire = 604800) { - $this->serializer = $serializer; - $this->connection = $connection; + function __construct(KeyValueExpirableFactoryInterface $storage_factory, LockBackendInterface $lockBackend, $expire = 604800) { + $this->storageFactory = $storage_factory; $this->lockBackend = $lockBackend; $this->expire = $expire; } @@ -86,7 +75,7 @@ class TempStoreFactory { } // Store the data for this collection in the database. - $storage = new DatabaseStorageExpirable($collection, $this->serializer, $this->connection); + $storage = $this->storageFactory->get("user.tempstore.$collection"); return new TempStore($storage, $this->lockBackend, $owner, $this->expire); } diff --git a/core/modules/user/src/Tests/TempStoreDatabaseTest.php b/core/modules/user/src/Tests/TempStoreDatabaseTest.php index 9a06b687133..ad6f56bf59e 100644 --- a/core/modules/user/src/Tests/TempStoreDatabaseTest.php +++ b/core/modules/user/src/Tests/TempStoreDatabaseTest.php @@ -8,6 +8,7 @@ namespace Drupal\user\Tests; use Drupal\Component\Serialization\PhpSerialize; +use Drupal\Core\KeyValueStore\KeyValueExpirableFactory; use Drupal\simpletest\KernelTestBase; use Drupal\user\TempStoreFactory; use Drupal\Core\Lock\DatabaseLockBackend; @@ -75,7 +76,7 @@ class TempStoreDatabaseTest extends KernelTestBase { */ public function testUserTempStore() { // Create a key/value collection. - $factory = new TempStoreFactory(new PhpSerialize(), Database::getConnection(), new DatabaseLockBackend(Database::getConnection())); + $factory = new TempStoreFactory(new KeyValueExpirableFactory(\Drupal::getContainer()), new DatabaseLockBackend(Database::getConnection())); $collection = $this->randomMachineName(); // Create two mock users. @@ -141,7 +142,7 @@ class TempStoreDatabaseTest extends KernelTestBase { // assert it is no longer accessible. db_update('key_value_expire') ->fields(array('expire' => REQUEST_TIME - 1)) - ->condition('collection', $collection) + ->condition('collection', "user.tempstore.$collection") ->condition('name', $key) ->execute(); $this->assertFalse($stores[0]->get($key)); diff --git a/core/modules/user/user.services.yml b/core/modules/user/user.services.yml index e89aa7368d4..3b6e4516e63 100644 --- a/core/modules/user/user.services.yml +++ b/core/modules/user/user.services.yml @@ -61,7 +61,7 @@ services: arguments: ['@entity.manager', '@password'] user.tempstore: class: Drupal\user\TempStoreFactory - arguments: ['@serialization.phpserialize', '@database', '@lock', '%user.tempstore.expire%'] + arguments: ['@keyvalue.expirable', '@lock', '%user.tempstore.expire%'] tags: - { name: backend_overridable } user.permissions: