You are here

function simple_ldap_user_user_delete in Simple LDAP 7.2

Same name and namespace in other branches
  1. 7 simple_ldap_user/simple_ldap_user.module \simple_ldap_user_user_delete()

Implements hook_user_delete().

Fires when a user account is deleted, before account is deleted.

@throw SimpleLdapException

File

simple_ldap_user/simple_ldap_user.module, line 373
Main simple_ldap_user module file.

Code

function simple_ldap_user_user_delete($account) {
  if ($account->uid == 1) {
    return;
  }

  // Call hook_simple_ldap_user_delete so other modules can create customized delete behavior.
  $ldap_user = SimpleLdapUser::singleton($account->name);
  $user_altered = array_filter(module_invoke_all('simple_ldap_user_delete', $account, $ldap_user));
  if (!empty($user_altered)) {
    try {
      $ldap_user
        ->save();
    } catch (SimpleLdapException $e) {
      watchdog('Simple LDAP', 'Failed to save changes to @dn from hook_simple_ldap_user_delete().', array(
        '@dn' => $ldap_user->dn,
        WATCHDOG_ERROR,
      ));
    }
  }
  if (!simple_ldap_user_variable_get('simple_ldap_user_delete_from_ldap')) {
    return;
  }
  try {
    $ldap_user
      ->delete();
  } catch (SimpleLdapException $e) {
    drupal_set_message(t('Failed to delete %name from LDAP.  Error @code: @message.', array(
      '%name' => $account->name,
      '@code' => $e
        ->getCode(),
      '@message' => $e
        ->getMessage(),
    )), 'error', FALSE);
  }
}