diff --git a/core/modules/user/src/PrivateTempStore.php b/core/modules/user/src/PrivateTempStore.php index 81503a4..63bc5bc 100644 --- a/core/modules/user/src/PrivateTempStore.php +++ b/core/modules/user/src/PrivateTempStore.php @@ -108,6 +108,13 @@ public function get($key) { /** * {@inheritdoc} */ + public function getIfOwner($key) { + return $this->get($key); + } + + /** + * {@inheritdoc} + */ public function set($key, $value) { $key = $this->createkey($key); if (!$this->lockBackend->acquire($key)) { @@ -132,6 +139,13 @@ public function set($key, $value) { /** * {@inheritdoc} */ + public function setIfOwner($key, $value) { + $this->set($key, $value); + } + + /** + * {@inheritdoc} + */ public function getMetadata($key) { $key = $this->createkey($key); // Fetch the key/value pair and its metadata. @@ -169,6 +183,13 @@ public function delete($key) { } /** + * {@inheritdoc} + */ + public function deleteIfOwner($key) { + return $this->delete($key); + } + + /** * Ensures that the key is unique for a user. * * @param string $key diff --git a/core/modules/user/src/SharedTempStore.php b/core/modules/user/src/SharedTempStore.php index e5d2492..706f5d2 100644 --- a/core/modules/user/src/SharedTempStore.php +++ b/core/modules/user/src/SharedTempStore.php @@ -114,18 +114,10 @@ public function get($key) { } /** - * Retrieves a value from this SharedTempStore for a given key. - * - * Only returns the value if the value is owned by $this->owner. - * - * @param string $key - * The key of the data to retrieve. - * - * @return mixed - * The data associated with the key, or NULL if the key does not exist. + * {@inheritdoc} */ public function getIfOwner($key) { - if (($object = $this->storage->get($key)) && ($object->owner == $this->owner)) { + if (($object = $this->storage->get($key)) && ($object->owner == $this->getOwner())) { return $object->data; } } @@ -143,7 +135,7 @@ public function getIfOwner($key) { */ public function setIfNotExists($key, $value) { $value = (object) array( - 'owner' => $this->owner, + 'owner' => $this->getOwner(), 'data' => $value, 'updated' => (int) $this->requestStack->getMasterRequest()->server->get('REQUEST_TIME'), ); @@ -151,26 +143,14 @@ public function setIfNotExists($key, $value) { } /** - * Stores a particular key/value pair in this SharedTempStore. - * - * Only stores the given key/value pair if it does not exist yet or is owned - * by $this->owner. - * - * @param string $key - * The key of the data to store. - * @param mixed $value - * The data to store. - * - * @return bool - * TRUE if the data was set, or FALSE if it already exists and is not owned - * by $this->user. + * {@inheritdoc} */ public function setIfOwner($key, $value) { if ($this->setIfNotExists($key, $value)) { return TRUE; } - if (($object = $this->storage->get($key)) && ($object->owner == $this->owner)) { + if (($object = $this->storage->get($key)) && ($object->owner == $this->getOwner())) { $this->set($key, $value); return TRUE; } @@ -193,7 +173,7 @@ public function set($key, $value) { } $value = (object) array( - 'owner' => $this->owner, + 'owner' => $this->getOwner(), 'data' => $value, 'updated' => (int) $this->requestStack->getMasterRequest()->server->get('REQUEST_TIME'), ); @@ -232,22 +212,13 @@ public function delete($key) { } /** - * Deletes data from the store for a given key and releases the lock on it. - * - * Only delete the given key if it is owned by $this->owner. - * - * @param string $key - * The key of the data to delete. - * - * @return bool - * TRUE if the object was deleted or does not exist, FALSE if it exists but - * is not owned by $this->owner. + * {@inheritdoc} */ public function deleteIfOwner($key) { if (!$object = $this->storage->get($key)) { return TRUE; } - elseif ($object->owner == $this->owner) { + elseif ($object->owner == $this->getOwner()) { $this->delete($key); return TRUE; } @@ -255,4 +226,11 @@ public function deleteIfOwner($key) { return FALSE; } + /** + * {@inheritdoc} + */ + protected function getOwner() { + return $this->owner; + } + } diff --git a/core/modules/user/src/TempStoreInterface.php b/core/modules/user/src/TempStoreInterface.php index 5f03b72..995cb97 100644 --- a/core/modules/user/src/TempStoreInterface.php +++ b/core/modules/user/src/TempStoreInterface.php @@ -24,6 +24,19 @@ public function get($key); /** + * Retrieves a value from this TempStore for a given key. + * + * Only returns the value if the value is owned by $this->getOwner(). + * + * @param string $key + * The key of the data to retrieve. + * + * @return mixed + * The data associated with the key, or NULL if the key does not exist. + */ + public function getIfOwner($key); + + /** * Stores a particular key/value pair in this TempStore. * * @param string $key @@ -34,6 +47,23 @@ public function get($key); public function set($key, $value); /** + * Stores a particular key/value pair in this TempStore. + * + * Only stores the given key/value pair if it does not exist yet or is owned + * by $this->getOwner(). + * + * @param string $key + * The key of the data to store. + * @param mixed $value + * The data to store. + * + * @return bool + * TRUE if the data was set, or FALSE if it already exists and is not owned + * by $this->user. + */ + public function setIfOwner($key, $value); + + /** * Returns the metadata associated with a particular key/value pair. * * @param string $key @@ -53,4 +83,18 @@ public function getMetadata($key); */ public function delete($key); + /** + * Deletes data from the store for a given key and releases the lock on it. + * + * Only delete the given key if it is owned by $this->getOwner(). + * + * @param string $key + * The key of the data to delete. + * + * @return bool + * TRUE if the object was deleted or does not exist, FALSE if it exists but + * is not owned by $this->getOwner(). + */ + public function deleteIfOwner($key); + }