Any clue how to refresh in proper way cached user->data object in 6.x?
#337182: Profile fields not updated in user data
user_save(user_load($node->uid));
doesn't work, because it's loading already cached data, and it's saving it over again
It's a bug?

Comments

Or module which updating some fields should unserialize and serialize those changes manually? It's quite stupid.

Status:Active» Closed (won't fix)

$user->data is not a cache, but a storage mechanism for modules that do not provide their own storage and use hook_user() to manage it. I'm not sure what you mean there.

I though it's kind of cache.
In example, Content Profile integrate content type fields with user object.
If one of the field has been updated, user object is not updated. So it have to load the user, update the fields and save it again.
So that's mean that module should update this storage mechanism manually?
Like: http://drupal.org/files/issues/profile_fields_not_updated.patch

Status:Closed (won't fix)» Fixed

Code to manually refresh some some custom fields into user object:

<?php
    $account
= user_load($node->uid);
   
$user_data = unserialize(db_result(db_query('SELECT data FROM {users} WHERE uid = %d', $node->uid)));
    foreach(
$user_data as $name => $value) {
      if(isset(
$node->$name)) {
       
$user_data[$name] = $node->$name;
      }
    }
   
user_save($account, $user_data);
?>

where $node->uid is the user id.
It can be use for integrating user profile. In example: content_profile module

Title:refresh cached user->datahow to update $user->data object

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

write:

  $my_custom_data = 123;
  global $user;
  user_save($user, array('my_custom_data' => $my_custom_data));

read:

  global $user;
  $my_custom_data = $user->my_custom_data;