You are here

function ldap_user_user_presave in Lightweight Directory Access Protocol (LDAP) 8.2

Same name and namespace in other branches
  1. 8.4 ldap_user/ldap_user.module \ldap_user_user_presave()
  2. 7.2 ldap_user/ldap_user.module \ldap_user_user_presave()

Implements hook_user_presave()

File

ldap_user/ldap_user.module, line 972
Module for the LDAP User Entity

Code

function ldap_user_user_presave(&$user_edit, $account, $category) {

  //debug("ldap_user_user_presave, category=$category"); debug($user_edit); debug($account); // ldap_user_user_insert, category='. $category . 'account->status = ' . $account->status);
  if (ldap_user_ldap_exclude($account, $user_edit)) {
    return;
  }
  if (isset($account->name)) {
    $drupal_username = $account->name;
  }
  elseif (!empty($user_edit['name'])) {
    $drupal_username = $user_edit['name'];
  }
  else {
    return;
  }
  $ldap_user_conf = ldap_user_conf();

  // check for provisioning to drupal and override synched user fields/props
  if ($ldap_user_conf->provisionsDrupalAccountsFromLdap && in_array(LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER, array_keys($ldap_user_conf->provisionsDrupalEvents))) {
    if (ldap_user_is_ldap_associated($account, LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER)) {
      $ldap_user = ldap_servers_get_user_ldap_data($drupal_username, $ldap_user_conf->drupalAcctProvisionServer, 'ldap_user_prov_to_drupal');
      $ldap_server = ldap_servers_get_servers($ldap_user_conf->drupalAcctProvisionServer, NULL, TRUE);
      $ldap_user_conf
        ->entryToUserEdit($ldap_user, $user_edit, $ldap_server, LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER, array(
        LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER,
      ));
    }
  }
}