diff --git a/core/lib/Drupal/Core/TempStore/SessionTempStore.php b/core/lib/Drupal/Core/TempStore/SessionTempStore.php index 297c4da..83475c2 100644 --- a/core/lib/Drupal/Core/TempStore/SessionTempStore.php +++ b/core/lib/Drupal/Core/TempStore/SessionTempStore.php @@ -15,16 +15,31 @@ class SessionTempStore extends TempStoreBase { /** * Overrides TempStoreBase::__construct(). */ - function __construct($subsystem, $sid = NULL) { - $this->subsystem = $subsystem; - $this->sid = isset($sid) ? $sid : session_id(); + function __construct($subsystem, $ownerId = NULL) { + $ownerId = isset($ownerId) ? $ownerId : session_id(); + parent::__construct($subsystem, $ownerId); + } + + /** + * Overrides TempStoreBase::set(). + */ + function set($key, $data) { + // Ensure that a session cookie is set for anonymous users. + if (!user_is_logged_in()) { + // A session is written so long as $_SESSION is not empty. Force this. + // @todo This feels really hacky. Is there a better way? + // @see http://drupalcode.org/project/ctools.git/blob/refs/heads/8.x-1.x:/includes/object-cache.inc#l69 + $_SESSION['temp_store_use_session'] = TRUE; + } + + parent::set($key, $data); } /** * Overrides TempStoreBase::getLockOwner(). */ public function getLockOwner($key, $exclude_owner = FALSE) { - $lock_owner = db_query('SELECT s.uid, t.updated FROM {temp_store} t INNER JOIN {sessions} s ON t.sid = s.sid WHERE t.subsystem = :subsystem AND t.temp_key = :temp_key ORDER BY t.updated ASC', array( + $lock_owner = db_query('SELECT s.uid, t.updated FROM {temp_store} t INNER JOIN {sessions} s ON t.ownerId = s.ownerId WHERE t.subsystem = :subsystem AND t.temp_key = :temp_key ORDER BY t.updated ASC', array( ':subsystem' => $this->subsystem, ':temp_key' => $key, ))->fetchObject(); diff --git a/core/lib/Drupal/Core/TempStore/SpecialTempStore.php b/core/lib/Drupal/Core/TempStore/SpecialTempStore.php index a49281d..b0fb8ac 100644 --- a/core/lib/Drupal/Core/TempStore/SpecialTempStore.php +++ b/core/lib/Drupal/Core/TempStore/SpecialTempStore.php @@ -14,26 +14,22 @@ class SpecialTempStore extends TempStoreBase { /** * Overrides TempStoreBase::__construct(). - * - * Since session IDs are not used, an exception is thrown if no identifier is - * provided. */ - function __construct($subsystem, $sid = NULL) { - if (!isset($sid)) { + function __construct($subsystem, $ownerId = NULL) { + // Since session IDs are not used, an exception is thrown if no + // identifier is provided. + if (!isset($ownerId)) { throw new TempStoreException(); } - $this->subsystem = $subsystem; - $this->sid = $sid; + parent::__construct($subsystem, $ownerId); } /** * Overrides TempStoreBase::getLockOwner(). - * - * Ignore the session table completely. */ public function getLockOwner($key, $exclude_owner = FALSE) { - return db_query('SELECT sid FROM {temp_store} WHERE subsystem = :subsystem AND temp_key = :temp_key', array( + return db_query('SELECT ownerId FROM {temp_store} WHERE subsystem = :subsystem AND temp_key = :temp_key', array( ':subsystem' => $this->subsystem, ':temp_key' => $key, ))->fetchField(); diff --git a/core/lib/Drupal/Core/TempStore/TempStoreBase.php b/core/lib/Drupal/Core/TempStore/TempStoreBase.php index 4637831..ccb848b 100644 --- a/core/lib/Drupal/Core/TempStore/TempStoreBase.php +++ b/core/lib/Drupal/Core/TempStore/TempStoreBase.php @@ -37,22 +37,21 @@ abstract class TempStoreBase { * * @var string */ - protected $sid; + protected $ownerId; /** - * Constructs a TempStore interaction object. + * Constructs a temporary storage object. * * @param string $subsystem * The module or subsystem. Possible values might include 'entity', * 'form', 'views', etc. - * - * @param string $sid - * (optional) A custom unique identifier for the owner of the TempStore - * data. If no custom identifier is provided, the current session ID is - * used. Defaults to NULL. + * @param string $ownerId + * (optional) A unique identifier for the owner of the temporary storage + * data. Defaults to NULL. */ - function __construct($subsystem, $sid = NULL) { + function __construct($subsystem, $ownerId = NULL) { $this->subsystem = $subsystem; + $this->ownerId = $ownerId; } /** @@ -68,9 +67,9 @@ abstract class TempStoreBase { // @todo We may wish to add static caching here in the future, either // as a static cache on the object or using drupal_static(). $data = db_query( - 'SELECT * FROM {temp_store} WHERE sid = :session_id AND subsystem = :subsystem AND temp_key = :temp_key', + 'SELECT * FROM {temp_store} WHERE ownerId = :session_id AND subsystem = :subsystem AND temp_key = :temp_key', array( - ':session_id' => $this->sid, + ':session_id' => $this->ownerId, ':subsystem' => $this->subsystem, ':temp_key' => $key, ) @@ -97,21 +96,13 @@ abstract class TempStoreBase { * to create multiple new objects simultaneously. Document a workaround? */ function set($key, $data) { - // Ensure that a session cookie is set for anonymous users. - if (!user_is_logged_in()) { - // A session is written so long as $_SESSION is not empty. Force this. - // @todo This feels really hacky. Is there a better way? - // @see http://drupalcode.org/project/ctools.git/blob/refs/heads/8.x-1.x:/includes/object-cache.inc#l69 - $_SESSION['temp_store_use_session'] = TRUE; - } - // Clear any existing data for this key. $this->delete($key); // Store the new data. db_insert('temp_store') ->fields(array( - 'sid' => $this->sid, + 'ownerId' => $this->ownerId, 'subsystem' => $this->subsystem, 'temp_key' => $key, 'data' => serialize($data), @@ -160,7 +151,7 @@ abstract class TempStoreBase { ->condition('subsystem', $this->subsystem); if (!$all) { - $query->condition('sid', $this->sid); + $query->condition('ownerId', $this->ownerId); } $query->execute(); @@ -196,7 +187,7 @@ abstract class TempStoreBase { * TempStoreBase::set() for details. */ public static function testStoredObjects($subsystem, $keys) { - return db_query("SELECT t.temp_key, s.uid, t.updated FROM {temp_store} t INNER JOIN {sessions} s ON t.sid = s.sid WHERE t.subsystem = :subsystem AND t.temp_key IN (:keys) ORDER BY t.updated ASC", array(':subsystem' => $subsystem, ':temp_keys' => $keys)) + return db_query("SELECT t.temp_key, s.uid, t.updated FROM {temp_store} t INNER JOIN {sessions} s ON t.ownerId = s.ownerId WHERE t.subsystem = :subsystem AND t.temp_key IN (:keys) ORDER BY t.updated ASC", array(':subsystem' => $subsystem, ':temp_keys' => $keys)) ->fetchAllAssoc('temp_key'); } diff --git a/core/modules/system/system.install b/core/modules/system/system.install index d4915a6..4a62a53 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -1376,7 +1376,7 @@ function system_schema() { $schema['temp_store'] = array( 'description' => t('A special cache used to store objects that are being edited; it serves to save state in an ordinarily stateless environment.'), 'fields' => array( - 'sid' => array( + 'ownerId' => array( 'type' => 'varchar', 'length' => '64', 'not null' => TRUE, @@ -1408,7 +1408,7 @@ function system_schema() { 'serialize' => TRUE, ), ), - 'primary key' => array('sid', 'subsystem', 'temp_key'), + 'primary key' => array('ownerId', 'subsystem', 'temp_key'), 'indexes' => array('updated' => array('updated')), ); @@ -1970,7 +1970,7 @@ function system_update_8011() { $table = array( 'description' => t('A special cache used to store objects that are being edited; it serves to save state in an ordinarily stateless environment.'), 'fields' => array( - 'sid' => array( + 'ownerId' => array( 'type' => 'varchar', 'length' => '64', 'not null' => TRUE, @@ -2002,7 +2002,7 @@ function system_update_8011() { 'serialize' => TRUE, ), ), - 'primary key' => array('sid', 'subsystem', 'temp_key'), + 'primary key' => array('ownerId', 'subsystem', 'temp_key'), 'indexes' => array('updated' => array('updated')), );