? 574194-bakery-store-slave-uid.patch
? 932774_better_profile_saving.patch
? 956316-bakery-notices_0.patch
Index: bakery.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/bakery/bakery.module,v
retrieving revision 1.52.4.10
diff -u -p -r1.52.4.10 bakery.module
--- bakery.module	12 Nov 2010 19:43:00 -0000	1.52.4.10
+++ bakery.module	16 Nov 2010 01:31:55 -0000
@@ -979,13 +979,28 @@ function bakery_eat_stroopwafel_cookie()
   else {
     drupal_set_header('X-Drupal-bakery-UID: ' . $account->uid);
 
+    // We manually save profile fields along the way.
     $fields = array();
+    $profile_fields = bakery_get_profile_fields();
     foreach (variable_get('bakery_supported_fields', array('mail' => 'mail', 'name' => 'name')) as $type => $value) {
       if ($value) {
-        $fields[$type] = isset($stroopwafel[$type]) ? $stroopwafel[$type] : $account->$type;
+        if (isset($stroopwafel[$type])) {
+          $fields[$type] = $stroopwafel[$type];
+
+          // If it's a profile field, handle differently.
+          if (array_key_exists($type, $profile_fields)) {
+            db_query("DELETE FROM {profile_values} WHERE fid = %d AND uid = %d", $profile_fields[$type], $account->uid);
+            db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", $profile_fields[$type], $account->uid, $stroopwafel[$type]);
+            // Since we've saved it, nothing to do here.
+            unset($fields[$type]);
+          }
+        }
+        else {
+          $fields[$type] = $account->$type;
+        }
       }
     }
-    $status = user_save($account, $fields, $stroopwafel['category']);
+    $status = user_save($account, $fields);
     if ($status === FALSE) {
       watchdog('bakery', 'User update from name %name_old to %name_new, mail %mail_old to %mail_new failed.', array('%name_old' => $account->name, '%name_new' => $stroopwafel['name'], '%mail_old' => $account->mail, '%mail_new' => $stroopwafel['mail']), WATCHDOG_ERROR);
       $message = t('There was a problem updating your account on %slave. Please contact the administrator.', array('%slave' => variable_get('site_name', '')));
@@ -1003,6 +1018,20 @@ function bakery_eat_stroopwafel_cookie()
 }
 
 /**
+ * Gets data about profile fields regarldess of category and is public.
+ * @return array keyed on fid with a value of the field name.
+ */
+function bakery_get_profile_fields() {
+  $return = array();
+  $results = db_query("SELECT fid, name FROM {profile_fields}");
+  while ($result = db_fetch_object($results)) {
+    watchdog('result', var_export($result, true));
+    $return[$result->name] = $result->fid;
+  }
+  return $return;
+}
+
+/**
  * Verify the validation request.
  */
 function bakery_taste_thinmint_cookie() {
