I don't know whether this belongs as an issue for Profile, Views, Drupal Core (5.1) or whether it belongs here.

When converting from 4.7 5o 5.1 the values for profile variables (variables created with the profile.module) remain serialized in the "data" field of the users table. At least until one manually edits the user profile. When one manually edits and saves a user's profile, the profile variables (of the specific category being displayed) are stored in the profile_values table.

Views, when told to print a profile field, will look in the profile_values table joined on the profile_fields table and joined on uid for the appropriate field. If that field remains in the users table, stuck in the serialized information of the "data" field, and not yet placed into the profile_values table, then Views displays nothing.

I would think that Node Profile should course through the defined profile fields and find the corresponding information in the "data" field of the users table and then build the appropriate rows in the profile_values tables.

Until then, the only solutions are:

1) Manually edit and save each separate category of a user's profile (this might be very painful; or, at least, time consuming).

2) Write a php snippet which accomplishes moving the data. If I get time I'll try to do that, but I doubt I'll be able to get it done soon (although one never knows).

Comments

drupal777’s picture

Project: Node Profile » Usernode
Version: 5.x-1.1 » 5.x-1.2

Moved from Node Profile. It didn't belong there.

fago’s picture

Project: Usernode » Views (for Drupal 7)
Version: 5.x-1.2 » 5.x-1.x-dev
Priority: Critical » Normal

nodeprofile has nothing to do with the core profile module, usernode too, it just helps a bit with views integration for users.
You are facing a problem with the views' (core) profile integration - so I set this issue to views.

however, I don't think that there will be much hope for this to be fixed..
Better re-save all user profiles with a script or so.

drupal777’s picture

This appears to be related to a Drupal core bug that is being fixed in 5.2.

See http://drupal.org/node/119114

merlinofchaos’s picture

I don't think I see how this is a Views issue, but I'm not sure whose issue it really IS.

drupal777’s picture

Well, here's one way to "fix" the problem, but it may not be the most efficient. Just put it into a node with php filter assigned and visit the node. One word of warning, though: if you have notify set to, er, notify folks (like the site administrator) when a user edits their profile, this snippet will generate an email for each user FOR EACH CATEGORY. So, if you have 1000 users and 10 categories of information on their profile page, you are looking for 10000 emails each time you run this code. YOU HAVE BEEN WARNED - if I knew of a way to set notify off temporarily, I would do that (disable the SMTP settings might work). In any event, here it is:

$categories = profile_categories();

  $output .= "Starting user profile update";
// next line can be modified if you want to just run one first as a test
  $result = db_query("SELECT uid FROM {users} WHERE uid>1 AND uid<10000");
  $list = array();
  while ($record = db_fetch_object($result)) {
    if ($record->uid == 0) continue;
    $account = user_load(array('uid' => $record->uid));
    profile_load_profile($account);

    $userdata = db_query("SELECT data FROM {users} WHERE uid = %d", $record->uid);

// The userdata fetch is different in different versions. I forget which works where, although I suspect that the one I have left uncommented is for 5.1 and the other is for 4.7.

//    $userdata = unserialize(db_fetch_object($userdata)->data);

$test = db_fetch_object($userdata);
$userdata = unserialize($test->data);

    if (!$userdata) $userdata = array();
   
    foreach ($categories as $category) {
      $data = array();
      $values = db_query("SELECT * FROM {profile_fields} pf INNER JOIN {profile_values} pv ON (pf.fid = pv.fid) WHERE pf.category = '%s' && pv.uid = %d", $category['name'], $account->uid);
      while ($value = db_fetch_object($values)) {
        $data[$value->name] =  $value->value;
      }
      $data = array_merge($data, (array)$userdata);
      user_save($account, $data, $category['name']);
    }
    $list[] = ("Updated " . theme('username', $account));
  }
  $output .= theme('item_list', $list);
  return $output;
sun’s picture

Status: Active » Closed (won't fix)

This seems to be caused by #119114: Profile values inconsistently saved.
I do not think that Views is able to fix this in any way.