diff --git a/core/lib/Drupal/Core/TempStore/TempStore.php b/core/lib/Drupal/Core/TempStore/TempStore.php index 708d13e..8e6d671 100644 --- a/core/lib/Drupal/Core/TempStore/TempStore.php +++ b/core/lib/Drupal/Core/TempStore/TempStore.php @@ -87,11 +87,11 @@ class TempStore { // @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 key = :key', + 'SELECT * FROM {temp_store} WHERE sid = :session_id AND subsystem = :subsystem AND temp_key = :temp_key', array( ':session_id' => $this->sid, ':subsystem' => $this->subsystem, - ':key' => $key, + ':temp_key' => $key, ) ) ->fetchObject(); @@ -132,7 +132,7 @@ class TempStore { ->fields(array( 'sid' => $this->sid, 'subsystem' => $this->subsystem, - 'key' => $key, + 'temp_key' => $key, 'data' => serialize($data), 'updated' => REQUEST_TIME, )) @@ -175,7 +175,7 @@ class TempStore { // The query builder will automatically use an IN condition when an array // is passed. $query = db_delete('temp_store') - ->condition('key', $key) + ->condition('temp_key', $key) ->condition('subsystem', $this->subsystem); if (!$all) { @@ -197,16 +197,69 @@ class TempStore { * @return string|null * The user ID of the data owner if it is in use, or NULL otherwise. */ - function getLockOwner($key) { - return db_query( - 'SELECT s.uid, t.updated FROM {temp_store} t INNER JOIN {sessions} s ON t.sid = s.sid WHERE s.sid <> :session_id AND t.subsystem = :subsystem AND t.key = :key ORDER BY t.updated ASC', - array( - ':session_id' => $this->sid, - ':subsystem' => $this->subsystem, - ':key' => $key, + public function getLockOwner($key) { + if ($this->useSessionTable) { + $uid = db_query('SELECT s.uid FROM {temp_store} t INNER JOIN {sessions} s ON t.sid = s.sid WHERE s.sid <> :session_id AND t.subsystem = :subsystem AND t.temp_key = :temp_key ORDER BY t.updated ASC', + array( + ':session_id' => $this->sid, + ':subsystem' => $this->subsystem, + ':temp_key' => $key, + ) ) - ) - ->fetchObject(); + ->fetchField(); + } + else { + $uid = db_query("SELECT sid FROM {temp_store} WHERE subsystem = :subsystem AND temp_key = :temp_key", + array( + ':subsystem' => $this->subsystem, + ':temp_key' => $key, + ) + ) + ->fetchField(); + } + return $uid; + } + + /** + * Gets the temporary object status of multiple items. + * + * @param string $subsystem + * The module or subsystem. Possible values might include 'entity', + * 'form', 'views', etc. + * @param array $keys + * An array of keys of stored objects. See + * TempStore::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)) + ->fetchAllAssoc('temp_key'); } + /** + * Truncates all temporary objects with certain names in the subsystem. + * + * @param string $subsystem + * The module or subsystem. Possible values might include 'entity', + * 'form', 'views', etc. + * @param array $key + * The key to the stored object. See TempStore::set() for details. + */ + public static function clearAll($subsystem, $key) { } + + /** + * Truncates all temporary objects older than a certain age. + * + * @param int $age + * The minimum age of objects to remove, in seconds. For example, 86400 is + * one day. Defaults to 7 days. + */ + public static function clearOldObjects($age = NULL) { + if (!isset($age)) { + // 7 days. + $age = 86400 * 7; + } + db_delete('temp_store') + ->condition('updated', REQUEST_TIME - $age, '<') + ->execute(); + } } diff --git a/core/modules/system/system.install b/core/modules/system/system.install index e6ee5a7..d4915a6 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -1388,7 +1388,7 @@ function system_schema() { 'not null' => TRUE, 'description' => 'The type of the object this cache is attached to; this essentially represents the owner so that several sub-systems can use this cache.', ), - 'key' => array( + 'temp_key' => array( 'type' => 'varchar', 'length' => '128', 'not null' => TRUE, @@ -1408,7 +1408,7 @@ function system_schema() { 'serialize' => TRUE, ), ), - 'primary key' => array('sid', 'subsystem', 'key'), + 'primary key' => array('sid', 'subsystem', 'temp_key'), 'indexes' => array('updated' => array('updated')), ); @@ -1982,7 +1982,7 @@ function system_update_8011() { 'not null' => TRUE, 'description' => 'The type of the object this cache is attached to; this essentially represents the owner so that several sub-systems can use this cache.', ), - 'key' => array( + 'temp_key' => array( 'type' => 'varchar', 'length' => '128', 'not null' => TRUE, @@ -2002,7 +2002,7 @@ function system_update_8011() { 'serialize' => TRUE, ), ), - 'primary key' => array('sid', 'subsystem', 'key'), + 'primary key' => array('sid', 'subsystem', 'temp_key'), 'indexes' => array('updated' => array('updated')), );