You are here

function ldapdata_user_update in LDAP integration 5.2

Same name and namespace in other branches
  1. 5 ldapdata.module \ldapdata_user_update()
1 call to ldapdata_user_update()
ldapdata_user in ./ldapdata.module
Implements hook_user()

File

./ldapdata.module, line 574

Code

function ldapdata_user_update(&$edit, &$user, $category) {
  global $ldap;
  if (!$user->ldap_authentified) {
    return;
  }

  // Three cases here:
  //   1. User logged on and editing his LDAP entry attributes ($category == LDAP_CATEGORY_USER_DATA).
  //   2. User logged on and editing his Drupal account settings ($category == 'account').
  //   3. OBSOLETE FROM 4.7: Password lost and being updated (category == 'account').
  // Additionally:
  //   4. User logged on and editing his profile.module fields ($category == *any*).
  $writeout = array();

  // So, case 1
  $editables = _ldapdata_ldap_info($user, 'ldapdata_rwattrs');
  if ($category == LDAP_CATEGORY_USER_DATA && $editables) {
    $writeout = array_merge($writeout, ldapdata_user_update_ldap_attributes($edit, $user));
  }
  else {
    if ($category == 'account') {
      $writeout = array_merge($writeout, ldapdata_user_update_drupal_account($edit, $user));
    }
  }

  // And now, case 4
  $writeout = array_merge($writeout, ldapdata_user_update_profile($edit, $user));
  if ($writeout) {
    $bind_info = _ldapdata_edition($user);
    if (!$ldap
      ->connect($bind_info[0], $bind_info[1])) {
      watchdog('user', "User update: user {$user->name}'s data could not be updated in the LDAP directory", WATCHDOG_NOTICE);
      return;
    }
    $ldap
      ->writeAttributes($user->ldap_dn, $writeout);
  }
  $ldap
    ->disconnect();
}