You are here

function ldap_user_user_presave in Lightweight Directory Access Protocol (LDAP) 7.2

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

Implements hook_user_presave()

File

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

Code

function ldap_user_user_presave(&$user_edit, $account, $category) {
  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();
  ldap_user_reset_provision_server($ldap_user_conf, $account);

  // Check for provisioning to drupal and override synched user fields/props
  // Provision from LDAP if a new account was not just provisioned from LDAP.
  if (ldap_user_ldap_provision_semaphore('drupal_created', 'get', $drupal_username) === FALSE) {
    if ($ldap_user_conf->provisionsDrupalAccountsFromLdap && in_array(LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER, array_keys($ldap_user_conf->provisionsDrupalEvents))) {
      if ($ldap_user_conf
        ->provisionEnabled(LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER, LDAP_USER_DRUPAL_USER_PROV_ON_USER_UPDATE_CREATE)) {
        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');
          if ($ldap_user) {
            $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, [
              LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER,
            ]);
          }
        }
      }
    }
  }
}