Index: includes/session.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/session.inc,v retrieving revision 1.71 diff -u -p -r1.71 session.inc --- includes/session.inc 5 Sep 2009 13:05:30 -0000 1.71 +++ includes/session.inc 24 Sep 2009 03:50:30 -0000 @@ -102,9 +102,6 @@ function _drupal_session_read($sid) { // We found the client's session record and they are an authenticated user. if ($user && $user->uid > 0) { - // This is done to unserialize the data member of $user. - $user = drupal_unpack($user); - // Add roles element to $user. $user->roles = array(); $user->roles[DRUPAL_AUTHENTICATED_RID] = 'authenticated user'; Index: modules/comment/comment.module =================================================================== RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v retrieving revision 1.774 diff -u -p -r1.774 comment.module --- modules/comment/comment.module 22 Sep 2009 07:36:57 -0000 1.774 +++ modules/comment/comment.module 24 Sep 2009 03:26:06 -0000 @@ -1479,13 +1479,12 @@ class CommentController extends DrupalDe $this->query->addField('n', 'type', 'node_type'); $this->query->innerJoin('users', 'u', 'base.uid = u.uid'); $this->query->addField('u', 'name', 'registered_name'); - $this->query->fields('u', array( 'uid', 'signature', 'picture', 'data', 'status')); + $this->query->fields('u', array( 'uid', 'signature', 'picture', 'status')); } protected function attachLoad(&$comments) { // Setup standard comment properties. foreach ($comments as $key => $comment) { - $comment = drupal_unpack($comment); $comment->name = $comment->uid ? $comment->registered_name : $comment->name; $comment->new = node_mark($comment->nid, $comment->timestamp); $comment->node_type = 'comment_node_' . $comment->node_type; Index: modules/comment/comment.pages.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/comment/comment.pages.inc,v retrieving revision 1.25 diff -u -p -r1.25 comment.pages.inc --- modules/comment/comment.pages.inc 11 Sep 2009 13:37:52 -0000 1.25 +++ modules/comment/comment.pages.inc 24 Sep 2009 03:27:12 -0000 @@ -48,7 +48,7 @@ function comment_reply($node, $pid = NUL // $pid indicates that this is a reply to a comment. if ($pid) { // Load the comment whose cid = $pid - $comment = db_query('SELECT c.*, u.uid, u.name AS registered_name, u.signature, u.picture, u.data FROM {comment} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = :cid AND c.status = :status', array( + $comment = db_query('SELECT c.*, u.uid, u.name AS registered_name, u.signature, u.picture FROM {comment} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = :cid AND c.status = :status', array( ':cid' => $pid, ':status' => COMMENT_PUBLISHED, ))->fetchObject(); @@ -61,7 +61,6 @@ function comment_reply($node, $pid = NUL drupal_goto("node/$node->nid"); } // Display the parent comment - $comment = drupal_unpack($comment); $comment->node_type = 'comment_node_' . $node->type; field_attach_load('comment', array($comment->cid => $comment)); $comment->name = $comment->uid ? $comment->registered_name : $comment->name; Index: modules/user/user.install =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.install,v retrieving revision 1.29 diff -u -p -r1.29 user.install --- modules/user/user.install 18 Sep 2009 00:04:24 -0000 1.29 +++ modules/user/user.install 24 Sep 2009 02:50:47 -0000 @@ -193,13 +193,6 @@ function user_schema() { 'default' => '', 'description' => 'Email address used for initial account creation.', ), - 'data' => array( - 'type' => 'text', - 'not null' => FALSE, - 'size' => 'big', - 'serialize' => TRUE, - 'description' => 'A serialized array of name value pairs that are related to the user. Any form values posted during user edit are stored and are loaded into the $user object during user_load(). Use of this field is discouraged and it will likely disappear in a future version of Drupal.', - ), ), 'indexes' => array( 'access' => array('access'), @@ -212,6 +205,39 @@ function user_schema() { 'primary key' => array('uid'), ); + $schema['users_data'] = array( + 'description' => 'Stores named variable/value pairs per user. Any form values posted during user edit are stored and loaded into the $user object during user_load(). All variables are loaded and cached in memory when a user is loaded, so developers should not be careless about what is stored here.', + 'fields' => array( + 'uid' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + 'description' => 'Primary Key: {users}.uid for user.', + ), + 'name' => array( + 'description' => 'The name of the variable.', + 'type' => 'varchar', + 'length' => 128, + 'not null' => TRUE, + 'default' => '', + ), + 'value' => array( + 'description' => 'The serialized value of the variable.', + 'type' => 'text', + 'not null' => TRUE, + 'size' => 'big', + ), + ), + 'primary key' => array('uid', 'name'), + 'indexes' => array( + 'name' => array('name'), + ), + 'foreign keys' => array( + 'uid' => array('users' => 'uid'), + ), + ); + $schema['users_roles'] = array( 'description' => 'Maps users to roles.', 'fields' => array( @@ -298,7 +324,6 @@ function user_update_7000(&$sandbox) { * * These fields were previously used to store per-user comment settings. */ - function user_update_7001() { $ret = array(); db_drop_field($ret, 'users', 'threshold'); @@ -482,6 +507,69 @@ function user_update_7004(&$sandbox) { } /** + * Move {users}.data into an own {users_data} table. + */ +function user_update_7005() { + $ret = array(); + // Create new {users_data} table. + db_create_table($ret, 'users_data', array( + 'description' => 'Stores named variable/value pairs per user. All variables are loaded and cached in memory when a user is loaded, so developers should not be careless about what is stored here.', + 'fields' => array( + 'uid' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + 'description' => 'Primary Key: {users}.uid for user.', + ), + 'name' => array( + 'description' => 'The name of the variable.', + 'type' => 'varchar', + 'length' => 128, + 'not null' => TRUE, + 'default' => '', + ), + 'value' => array( + 'description' => 'The value of the variable.', + 'type' => 'text', + 'not null' => TRUE, + 'size' => 'big', + ), + ), + 'primary key' => array('uid', 'name'), + 'indexes' => array( + 'name' => array('name'), + ), + 'foreign keys' => array( + 'uid' => array('users' => 'uid'), + ), + )); + + // Migrate existing data. + $result = db_query("SELECT uid, data FROM {users}")->fetchAllAssoc('uid'); + $query = db_insert('users_data')->fields(array('uid', 'name', 'value')); + foreach ($result as $uid => $user) { + if (empty($user->data)) { + continue; + } + $result[$uid]->data = unserialize($result[$uid]->data); + if (is_array($result[$uid]->data)) { + foreach ($result[$uid]->data as $name => $value) { + $query->values(array( + 'uid' => $uid, + 'name' => $name, + 'value' => serialize($value), + )); + } + } + } + $query->execute(); + + // Delete {users}.data. + db_drop_field($ret, 'users', 'data'); +} + +/** * @} End of "defgroup user-updates-6.x-to-7.x" * The next series of updates should start at 8000. */ Index: modules/user/user.module =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.module,v retrieving revision 1.1052 diff -u -p -r1.1052 user.module --- modules/user/user.module 22 Sep 2009 15:26:46 -0000 1.1052 +++ modules/user/user.module 24 Sep 2009 04:46:29 -0000 @@ -200,7 +200,6 @@ class UserController extends DrupalDefau $picture_fids = array(); foreach ($queried_users as $key => $record) { $picture_fids[] = $record->picture; - $queried_users[$key] = drupal_unpack($record); $queried_users[$key]->roles = array(); if ($record->uid) { $queried_users[$record->uid]->roles[DRUPAL_AUTHENTICATED_RID] = 'authenticated user'; @@ -210,6 +209,12 @@ class UserController extends DrupalDefau } } + // Attach user variables. + $data = db_query("SELECT uid, name, value FROM {users_data} WHERE uid IN (:uids)", array(':uids' => array_keys($queried_users))); + foreach ($data as $record) { + $queried_users[$record->uid]->{$record->name} = unserialize($record->value); + } + // Add any additional roles from the database. $result = db_query('SELECT r.rid, r.name, ur.uid FROM {role} r INNER JOIN {users_roles} ur ON ur.rid = r.rid WHERE ur.uid IN (:uids)', array(':uids' => array_keys($queried_users))); foreach ($result as $record) { @@ -342,7 +347,6 @@ function user_save($account, $edit = arr } if (is_object($account) && !$account->is_new) { user_module_invoke('update', $edit, $account, $category); - $data = unserialize(db_query('SELECT data FROM {users} WHERE uid = :uid', array(':uid' => $account->uid))->fetchField()); // Consider users edited by an administrator as logged in, if they haven't // already, so anonymous users can view the profile (if allowed). if (empty($edit['access']) && empty($account->access) && user_access('administer users')) { @@ -354,10 +358,13 @@ function user_save($account, $edit = arr // column. if (!in_array($key, array('roles', 'is_new')) && empty($user_fields[$key]) && empty($field_form[$key])) { if ($value === NULL) { - unset($data[$key]); + db_query("DELETE FROM {users_data} WHERE uid = :uid AND name = :name", array(':uid' => $account->uid, ':name' => $key)); } else { - $data[$key] = $value; + db_merge('users_data') + ->key(array('uid' => $account->uid, 'name' => $key)) + ->fields(array('value' => serialize($value))) + ->execute(); } } } @@ -383,7 +390,6 @@ function user_save($account, $edit = arr } $edit['picture'] = empty($edit['picture']->fid) ? 0 : $edit['picture']->fid; - $edit['data'] = $data; // Do not allow 'uid' to be changed. $edit['uid'] = $account->uid; // Save changes to the user table. @@ -483,19 +489,17 @@ function user_save($account, $edit = arr // Note, we wait with saving the data column to prevent module-handled // fields from being saved there. - $data = array(); foreach ($edit as $key => $value) { // Form fields that don't pertain to the users, user_roles, or // Field API are automatically serialized into the user.data // column. if ((!in_array($key, array('roles', 'is_new'))) && (empty($user_fields[$key]) && empty($field_form[$key])) && ($value !== NULL)) { - $data[$key] = $value; + db_merge('users_data') + ->key(array('uid' => $user->uid, 'name' => $key)) + ->fields(array('value' => serialize($value))) + ->execute(); } } - if (!empty($data)) { - $data_array = array('uid' => $user->uid, 'data' => $data); - drupal_write_record('users', $data_array, 'uid'); - } // Save user roles (delete just to be safe). if (isset($edit['roles']) && is_array($edit['roles'])) { @@ -2889,13 +2893,12 @@ function user_node_load($nodes, $types) } // Fetch name, picture, and data for these users. - $user_fields = db_query("SELECT uid, name, picture, data FROM {users} WHERE uid IN (:uids)", array(':uids' => $uids))->fetchAllAssoc('uid'); + $user_fields = db_query("SELECT uid, name, picture FROM {users} WHERE uid IN (:uids)", array(':uids' => $uids))->fetchAllAssoc('uid'); // Add these values back into the node objects. foreach ($uids as $nid => $uid) { $nodes[$nid]->name = $user_fields[$uid]->name; $nodes[$nid]->picture = $user_fields[$uid]->picture; - $nodes[$nid]->data = $user_fields[$uid]->data; } }