You are here

function profile_user_import_save_profile in User Import 8

Same name and namespace in other branches
  1. 5.2 supported/profile.inc \profile_user_import_save_profile()
  2. 5 supported/profile.inc \profile_user_import_save_profile()
  3. 6.4 supported/profile.inc \profile_user_import_save_profile()
  4. 6.2 supported/profile.inc \profile_user_import_save_profile()
  5. 7 supported/profile.inc \profile_user_import_save_profile()
  6. 7.2 supported/profile.inc \profile_user_import_save_profile()
1 call to profile_user_import_save_profile()
profile_user_import_after_save in supported/profile.inc
Implementation of hook_user_import_after_save().

File

supported/profile.inc, line 59

Code

function profile_user_import_save_profile($field, $uid, $value, $updated, $update_setting, &$data) {

  // when the profile field is displayed on the registration form an empty value is automatically saved by the Profile module
  $exists = db_query_range('SELECT value FROM {profile_values} WHERE fid = :fid AND uid = :uid', 0, 1, array(
    ':fid' => $field->fid,
    ':uid' => $uid,
  ))
    ->fetchField();
  user_import_profile_date($value, $field->type);
  if ($updated) {
    switch ($update_setting) {
      case UPDATE_NONE:
        return;
      case UPDATE_ADD:
        if (empty($value) || !empty($exists) && $exists != '') {
          return;
        }
      case UPDATE_REPLACE:
        if (empty($value) && $update_setting == UPDATE_REPLACE) {
          db_query("DELETE FROM {profile_values} WHERE fid = :fid AND uid = :uid", array(
            ':fid' => $field->fid,
            ':uid' => $uid,
          ));
          unset($data[$field->name]);
          return;
        }
        if (empty($exists) && $exists != '' || $exists === FALSE) {
          $id = db_insert('profile_values')
            ->fields(array(
            'fid' => $field->fid,
            'uid' => $uid,
            'value' => $value,
          ))
            ->execute();
        }
        else {
          $id = db_update('profile_values')
            ->fields(array(
            'value' => $value,
          ))
            ->condition('fid', $field->fid)
            ->condition('uid', $uid)
            ->execute();
        }
        $data[$field->name] = $value;
        return;
    }
  }
  else {
    if (empty($value)) {
      return;
    }
    if (empty($exists) && $exists != '' || $exists === FALSE) {
      $id = db_insert('profile_values')
        ->fields(array(
        'fid' => $field->fid,
        'uid' => $uid,
        'value' => $value,
      ))
        ->execute();
    }
    else {
      db_update('profile_values')
        ->fields(array(
        'value' => $value,
      ))
        ->condition('fid', $field->fid)
        ->condition('uid', $uid)
        ->limit(1)
        ->execute();
      $data[$field->name] = $value;
    }
  }
  return;
}