You are here

function ldap_user_user_update 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_update()
  2. 8.3 ldap_user/ldap_user.module \ldap_user_user_update()
  3. 7.2 ldap_user/ldap_user.module \ldap_user_user_update()

Implements hook_user_update()

File

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

Code

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

  //debug("ldap_user_user_update, 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;
  }
  $ldap_user_conf = ldap_user_conf();

  // check for provisioning to LDAP; this will normally occur on hook_user_insert or other event when drupal user is created.
  if ($ldap_user_conf->provisionsLdapEntriesFromDrupalUsers && $ldap_user_conf
    ->provisionEnabled(LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY, LDAP_USER_LDAP_ENTRY_PROV_ON_USER_UPDATE_CREATE)) {
    $already_provisioned_to_ldap = ldap_user_ldap_provision_semaphore('provision', 'get', $account->name);
    $already_synched_to_ldap = ldap_user_ldap_provision_semaphore('synch', 'get', $account->name);
    if ($already_provisioned_to_ldap || $already_synched_to_ldap) {
      return;
    }
    $provision_result = array(
      'status' => 'none',
    );

    // always check if provisioning to ldap has already occurred this page load
    $ldap_entry = $ldap_user_conf
      ->getProvisionRelatedLdapEntry($account);
    if (!$ldap_entry) {

      //{
      $provision_result = $ldap_user_conf
        ->provisionLdapEntry($account);
      if ($provision_result['status'] == 'success') {
        ldap_user_ldap_provision_semaphore('provision', 'set', $account->name);
      }
    }

    // synch if not just provisioned and enabled
    if ($provision_result['status'] != 'success') {

      // always check if provisioing to ldap has already occurred this page load
      $provision_enabled = $ldap_user_conf
        ->provisionEnabled(LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY, LDAP_USER_LDAP_ENTRY_PROV_ON_USER_UPDATE_CREATE);
      $ldap_entry = $ldap_user_conf
        ->getProvisionRelatedLdapEntry($account);
      if ($provision_enabled && $ldap_entry) {
        $bool_result = $ldap_user_conf
          ->synchToLdapEntry($account, $user_edit);
        if ($bool_result) {
          ldap_user_ldap_provision_semaphore('synch', 'set', $account->name);
        }
      }
    }
  }
}