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

kenorb’s picture

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

Damien Tournoud’s picture

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.

kenorb’s picture

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

kenorb’s picture

Status: Closed (won't fix) » Fixed

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

    $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

kenorb’s picture

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

Status: Fixed » Closed (fixed)

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

pieter_duijves’s picture

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;
pdcarto’s picture

Issue summary: View changes

I tried storing entity data (membership_entity) in the user's data property and discovered that will not work because that entity type's controller does not yet exist when the user is loaded.