You are here

function bakery_prepare_fields in Bakery Single Sign-On System 6.2

Prepare fields for user_save().

Parameters

$cookie: Associative array of values to update from the incoming cookie.

$account: A local user object.

Return value

Associative array suitable for the second argument of user_save().

2 calls to bakery_prepare_fields()
bakery_eat_stroopwafel_cookie in ./bakery.module
Menu callback, invoked on the slave
bakery_request_account in ./bakery.module
Request account information from master to create account locally.

File

./bakery.module, line 1264

Code

function bakery_prepare_fields($cookie, $account) {
  $fields = array();
  $profile_fields = bakery_get_profile_fields();
  foreach (array_keys(array_filter(variable_get('bakery_supported_fields', array(
    'mail' => 'mail',
    'name' => 'name',
  )))) as $type) {

    // If the field is set in the cookie it's being updated, otherwise we'll
    // populate $fields with the existing values so nothing is lost.
    if (isset($cookie[$type])) {

      // If it's a profile field, handle ourselves to avoid {users}.data.
      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, $cookie[$type]);
      }
      else {
        $fields[$type] = $cookie[$type];
      }
    }
    else {
      $fields[$type] = $account->{$type};
    }
  }
  return $fields;
}