You are here

function janrain_capture_profile_sync in Janrain Registration 7

Same name and namespace in other branches
  1. 6 janrain_capture.pages.inc \janrain_capture_profile_sync()
  2. 7.4 includes/janrain_capture.endpoints.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 223
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;
  }

  // Make sure the account object is fully populated.
  $account = user_load($user->uid);
  janrain_capture_sync_account($account, $profile['result']);
  if ($account = user_save($account)) {
    $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);
  }
}