Issue #2405737 by chx: user.tempstore is unnecessary to be backend_overridable
parent
3df1005421
commit
1b2e7c4544
|
@ -8,7 +8,7 @@
|
||||||
namespace Drupal\Core\KeyValueStore;
|
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 {
|
class KeyValueMemoryFactory implements KeyValueFactoryInterface {
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,7 @@
|
||||||
namespace Drupal\user;
|
namespace Drupal\user;
|
||||||
|
|
||||||
use Drupal\Component\Serialization\SerializationInterface;
|
use Drupal\Component\Serialization\SerializationInterface;
|
||||||
use Drupal\Core\Database\Connection;
|
use Drupal\Core\KeyValueStore\KeyValueExpirableFactoryInterface;
|
||||||
use Drupal\Core\KeyValueStore\DatabaseStorageExpirable;
|
|
||||||
use Drupal\Core\Lock\LockBackendInterface;
|
use Drupal\Core\Lock\LockBackendInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -18,18 +17,11 @@ use Drupal\Core\Lock\LockBackendInterface;
|
||||||
class TempStoreFactory {
|
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;
|
protected $storageFactory;
|
||||||
|
|
||||||
/**
|
|
||||||
* The connection object used for this data.
|
|
||||||
*
|
|
||||||
* @var \Drupal\Core\Database\Connection $connection
|
|
||||||
*/
|
|
||||||
protected $connection;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The lock object used for this data.
|
* The lock object used for this data.
|
||||||
|
@ -48,8 +40,6 @@ class TempStoreFactory {
|
||||||
/**
|
/**
|
||||||
* Constructs a Drupal\user\TempStoreFactory object.
|
* Constructs a Drupal\user\TempStoreFactory object.
|
||||||
*
|
*
|
||||||
* @param \Drupal\Component\Serialization\SerializationInterface $serializer
|
|
||||||
* The serialization class to use.
|
|
||||||
* @param \Drupal\Core\Database\Connection $connection
|
* @param \Drupal\Core\Database\Connection $connection
|
||||||
* The connection object used for this data.
|
* The connection object used for this data.
|
||||||
* @param \Drupal\Core\Lock\LockBackendInterface $lockBackend
|
* @param \Drupal\Core\Lock\LockBackendInterface $lockBackend
|
||||||
|
@ -57,9 +47,8 @@ class TempStoreFactory {
|
||||||
* @param int $expire
|
* @param int $expire
|
||||||
* The time to live for items, in seconds.
|
* The time to live for items, in seconds.
|
||||||
*/
|
*/
|
||||||
function __construct(SerializationInterface $serializer, Connection $connection, LockBackendInterface $lockBackend, $expire = 604800) {
|
function __construct(KeyValueExpirableFactoryInterface $storage_factory, LockBackendInterface $lockBackend, $expire = 604800) {
|
||||||
$this->serializer = $serializer;
|
$this->storageFactory = $storage_factory;
|
||||||
$this->connection = $connection;
|
|
||||||
$this->lockBackend = $lockBackend;
|
$this->lockBackend = $lockBackend;
|
||||||
$this->expire = $expire;
|
$this->expire = $expire;
|
||||||
}
|
}
|
||||||
|
@ -86,7 +75,7 @@ class TempStoreFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store the data for this collection in the database.
|
// 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);
|
return new TempStore($storage, $this->lockBackend, $owner, $this->expire);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
namespace Drupal\user\Tests;
|
namespace Drupal\user\Tests;
|
||||||
|
|
||||||
use Drupal\Component\Serialization\PhpSerialize;
|
use Drupal\Component\Serialization\PhpSerialize;
|
||||||
|
use Drupal\Core\KeyValueStore\KeyValueExpirableFactory;
|
||||||
use Drupal\simpletest\KernelTestBase;
|
use Drupal\simpletest\KernelTestBase;
|
||||||
use Drupal\user\TempStoreFactory;
|
use Drupal\user\TempStoreFactory;
|
||||||
use Drupal\Core\Lock\DatabaseLockBackend;
|
use Drupal\Core\Lock\DatabaseLockBackend;
|
||||||
|
@ -75,7 +76,7 @@ class TempStoreDatabaseTest extends KernelTestBase {
|
||||||
*/
|
*/
|
||||||
public function testUserTempStore() {
|
public function testUserTempStore() {
|
||||||
// Create a key/value collection.
|
// 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();
|
$collection = $this->randomMachineName();
|
||||||
|
|
||||||
// Create two mock users.
|
// Create two mock users.
|
||||||
|
@ -141,7 +142,7 @@ class TempStoreDatabaseTest extends KernelTestBase {
|
||||||
// assert it is no longer accessible.
|
// assert it is no longer accessible.
|
||||||
db_update('key_value_expire')
|
db_update('key_value_expire')
|
||||||
->fields(array('expire' => REQUEST_TIME - 1))
|
->fields(array('expire' => REQUEST_TIME - 1))
|
||||||
->condition('collection', $collection)
|
->condition('collection', "user.tempstore.$collection")
|
||||||
->condition('name', $key)
|
->condition('name', $key)
|
||||||
->execute();
|
->execute();
|
||||||
$this->assertFalse($stores[0]->get($key));
|
$this->assertFalse($stores[0]->get($key));
|
||||||
|
|
|
@ -61,7 +61,7 @@ services:
|
||||||
arguments: ['@entity.manager', '@password']
|
arguments: ['@entity.manager', '@password']
|
||||||
user.tempstore:
|
user.tempstore:
|
||||||
class: Drupal\user\TempStoreFactory
|
class: Drupal\user\TempStoreFactory
|
||||||
arguments: ['@serialization.phpserialize', '@database', '@lock', '%user.tempstore.expire%']
|
arguments: ['@keyvalue.expirable', '@lock', '%user.tempstore.expire%']
|
||||||
tags:
|
tags:
|
||||||
- { name: backend_overridable }
|
- { name: backend_overridable }
|
||||||
user.permissions:
|
user.permissions:
|
||||||
|
|
Loading…
Reference in New Issue