diff --git a/core/lib/Drupal/Core/KeyValueStore/DatabaseStorage.php b/core/lib/Drupal/Core/KeyValueStore/DatabaseStorage.php index 6cca278..6c9fde2 100644 --- a/core/lib/Drupal/Core/KeyValueStore/DatabaseStorage.php +++ b/core/lib/Drupal/Core/KeyValueStore/DatabaseStorage.php @@ -6,6 +6,7 @@ */ namespace Drupal\Core\KeyValueStore; + use Drupal\Core\Database\Query\Merge; /** @@ -45,9 +46,9 @@ public function getMultiple(array $keys) { } } catch (\Exception $e) { - // @todo: Perhaps if the database is never going to be available, - // key/value requests should return FALSE in order to allow exception - // handling to occur but for now, keep it an array, always. + // @todo Perhaps if the database is never going to be available, + // key/value requests should return FALSE in order to allow exception + // handling to occur but for now, keep it an array, always. } return $values; } @@ -80,6 +81,9 @@ public function set($key, $value) { ->execute(); } + /** + * Implements Drupal\Core\KeyValueStore\KeyValueStoreInterface::setIfNotExists(). + */ public function setIfNotExists($key, $value) { $result = db_merge($this->table) ->insertFields(array( @@ -107,4 +111,5 @@ public function deleteMultiple(array $keys) { } while (count($keys)); } + } diff --git a/core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpire.php b/core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpire.php index ae0b3f8..acc917a 100644 --- a/core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpire.php +++ b/core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpire.php @@ -2,34 +2,43 @@ /** * @file - * Contains Drupal\Core\KeyValueStore\DatabaseStorage. + * Contains Drupal\Core\KeyValueStore\DatabaseStorageExpire. */ namespace Drupal\Core\KeyValueStore; + use Drupal\Core\Database\Query\Merge; - /** +/** * Defines a default key/value store implementation for expiring items. * * This is Drupal's default key/value store implementation. It uses the database * to store key/value data with an expire date. */ -/** - * - */ class DatabaseStorageExpire extends StorageBase implements KeyValueStoreExpireInterface { /** * The time to live for items in seconds. Defaults to a week. + * + * @var int */ protected $expire = 604800; /** - * @var Drupal\Core\Database\Connection $connection + * The connection object for this storage. + * + * @var Drupal\Core\Database\Connection */ protected $connection; /** + * The name of the SQL table to use. + * + * @var string + */ + protected $table; + + /** * Overrides Drupal\Core\KeyValueStore\StorageBase::__construct(). * * @param string $collection @@ -37,7 +46,7 @@ class DatabaseStorageExpire extends StorageBase implements KeyValueStoreExpireIn * @param array $options * An associative array of options for the key/value storage collection. * Keys used: - * - table. The name of the SQL table to use, defaults to key_value. + * - table. The name of the SQL table to use, defaults to key_value_expire. */ public function __construct($collection, array $options = array()) { parent::__construct($collection, $options); @@ -65,9 +74,9 @@ public function getMultiple(array $keys) { } } catch (\Exception $e) { - // @todo: Perhaps if the database is never going to be available, - // key/value requests should return FALSE in order to allow exception - // handling to occur but for now, keep it an array, always. + // @todo Perhaps if the database is never going to be available, + // key/value requests should return FALSE in order to allow exception + // handling to occur but for now, keep it an array, always. } return $values; } @@ -105,8 +114,7 @@ public function set($key, $value) { } /** - * @param string $key - * @param mixed $value + * Implements Drupal\Core\KeyValueStore\KeyValueStoreInterface::setIfNotExists(). */ public function setIfNotExists($key, $value) { $this->garbageCollection(); @@ -139,7 +147,7 @@ public function deleteMultiple(array $keys) { } /** - * Delete expired items. + * Deletes expired items. */ protected function garbageCollection() { $this->connection->delete($this->table) @@ -153,4 +161,5 @@ protected function garbageCollection() { public function setExpire($expire) { $this->expire = $expire; } + } diff --git a/core/lib/Drupal/Core/KeyValueStore/KeyValueStoreExpireInterface.php b/core/lib/Drupal/Core/KeyValueStore/KeyValueStoreExpireInterface.php index 4b339a1..fd50fe3 100644 --- a/core/lib/Drupal/Core/KeyValueStore/KeyValueStoreExpireInterface.php +++ b/core/lib/Drupal/Core/KeyValueStore/KeyValueStoreExpireInterface.php @@ -1,4 +1,5 @@ storage->get($key); if ($object) { unset($object->data); diff --git a/core/modules/user/lib/Drupal/user/KeyValueStoreWithOwnerException.php b/core/modules/user/lib/Drupal/user/KeyValueStoreWithOwnerException.php index 701e62e..4a35e23 100644 --- a/core/modules/user/lib/Drupal/user/KeyValueStoreWithOwnerException.php +++ b/core/modules/user/lib/Drupal/user/KeyValueStoreWithOwnerException.php @@ -11,4 +11,3 @@ * Exception thrown when KeyValueStoreWithOwner can not acquire a lock. */ class KeyValueStoreWithOwnerException extends \Exception {} - diff --git a/core/modules/user/lib/Drupal/user/Tests/TempStoreDatabaseTest.php b/core/modules/user/lib/Drupal/user/Tests/TempStoreDatabaseTest.php index 5cdfa9e..ae57966 100644 --- a/core/modules/user/lib/Drupal/user/Tests/TempStoreDatabaseTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/TempStoreDatabaseTest.php @@ -88,7 +88,8 @@ public function testUserTempStore() { $store = $this->getStorePerUid($this->users[$i]); // Setting twice results only in the first succeeding. $this->assertEqual(!$i, $store->setIfNotExists($key, $this->objects[$i])); - $this->assertEqual($this->users[0], $store->getOwner($key)); + $metadata = $store->getMetadata($key); + $this->assertEqual($this->users[0], $metadata->owner); $this->assertIdenticalObject($this->objects[0], $store->get($key)); } // Remove the item.