You are here

function janrain_capture_profile_sync in Janrain Registration 6

Same name and namespace in other branches
  1. 7.4 includes/janrain_capture.endpoints.inc \janrain_capture_profile_sync()
  2. 7 janrain_capture.pages.inc \janrain_capture_profile_sync()
  3. 7.2 includes/janrain_capture.endpoints.inc \janrain_capture_profile_sync()
  4. 7.3 includes/janrain_capture.endpoints.inc \janrain_capture_profile_sync()

Callback for the janrain_capture/profile_sync menu item. Retrieves the most recent data from Capture and stores values locally.

1 string reference to 'janrain_capture_profile_sync'
janrain_capture_menu in ./janrain_capture.module
Implements hook_menu().

File

./janrain_capture.pages.inc, line 210
User page callbacks for the janrain_capture module.

Code

function janrain_capture_profile_sync() {
  global $user;
  $api = new JanrainCaptureApi();
  $profile = $api
    ->loadUserEntity();
  if (!$profile) {
    drupal_set_message(t('We were unable to complete your request.'), 'error');
    watchdog('janrain_capture', 'Failed to obtain a Capture record', array(), WATCHDOG_ERROR);
    return;
  }
  $user_data = array(
    'name' => janrain_capture_profile_field($profile),
    'mail' => $profile['result']['email'],
  );
  $merged_data = janrain_capture_fields_array($user_data, $profile['result']);
  if ($account = user_save($user, $merged_data)) {
    $profile_updated_hook = module_invoke_all('janrain_capture_user_profile_updated', $profile['result'], $account);
    if (empty($profile_updated_hook) || !in_array(FALSE, $profile_updated_hook)) {
      drupal_goto();
    }
  }
  else {
    drupal_set_message(t('We were unable to complete your request.'), 'error');
    watchdog('janrain_capture', 'Failed to save Capture data to user', array(), WATCHDOG_ERROR);
  }
}