I noticed that the ldapdata.module file wasn't correctly updating the profile_values table in the database. Here's the original code starting on line 524...

// Write coincidences to Drupal DB
  foreach ($writeout as $field => $value) {
    $result = db_fetch_array(db_query("SELECT fid FROM {profile_fields} WHERE name = '%s'", $field));
    $fid = $result->fid;
    $uid = $user->uid;
	
    // does the user have a value for this field ? then update it : otherwise create it
    $result = db_fetch_array(db_query("SELECT value FROM {profile_values} WHERE fid = '%d' AND uid = '%d'", $fid, $uid));
    if ($result) {
      db_query("UPDATE {profile_values} SET value = '%s' WHERE fid = '%d' AND uid = '%d'", $value, $fid, $uid);
    }
    else {
      db_query("INSERT INTO {profile_values} (value, fid, uid) VALUES ('%s', '%d', '%d')", $value, $fid, $uid);
    }
  }

I was noticing that every time it would attempt to insert or update, the fid value was not being set correctly, so here's what i've done to fix it.

// Write coincidences to Drupal DB
  foreach ($writeout as $field => $value) {
    $result = db_fetch_array(db_query("SELECT fid FROM {profile_fields} WHERE name = '%s'", $field));
    $fid = $result['fid'];  // change noted here
    $uid = $user->uid;
	
    // does the user have a value for this field ? then update it : otherwise create it
    $result = db_fetch_array(db_query("SELECT value FROM {profile_values} WHERE fid = '%d' AND uid = '%d'", $fid, $uid));
    if ($result) {
      db_query("UPDATE {profile_values} SET value = '%s' WHERE fid = '%d' AND uid = '%d'", $value, $fid, $uid);
    }
    else {
      db_query("INSERT INTO {profile_values} (value, fid, uid) VALUES ('%s', '%d', '%d')", $value, $fid, $uid);
    }
  }

That fixed it for me!

Comments

kreaper’s picture

Assigned: Unassigned » kreaper
Status: Active » Fixed

Fixed in the HEAD. Thx!

Anonymous’s picture

Status: Fixed » Closed (fixed)