You are here

public function LdapUserConf::deleteProvisionedLdapEntries in Lightweight Directory Access Protocol (LDAP) 7.2

Same name and namespace in other branches
  1. 8.2 ldap_user/LdapUserConf.class.php \LdapUserConf::deleteProvisionedLdapEntries()

Given a drupal account, delete ldap entry that was provisioned based on it normally this will be 0 or 1 entry, but the ldap_user_provisioned_ldap_entries field attached to the user entity track each ldap entry provisioned.

Parameters

object $account: drupal account.

Return value

TRUE or FALSE. FALSE indicates failed or action not enabled in ldap user configuration

File

ldap_user/LdapUserConf.class.php, line 911

Class

LdapUserConf

Code

public function deleteProvisionedLdapEntries($account) {

  // Determine server that is associated with user.
  $boolean_result = FALSE;
  if (isset($account->ldap_user_prov_entries[LANGUAGE_NONE][0])) {
    foreach ($account->ldap_user_prov_entries[LANGUAGE_NONE] as $i => $field_instance) {
      $parts = explode('|', $field_instance['value']);
      if (count($parts) == 2) {
        list($sid, $dn) = $parts;
        $ldap_server = ldap_servers_get_servers($sid, NULL, TRUE);
        if (is_object($ldap_server) && $dn) {
          $boolean_result = $ldap_server
            ->delete($dn);
          $tokens = [
            '%sid' => $sid,
            '%dn' => $dn,
            '%username' => $account->name,
            '%uid' => $account->uid,
          ];
          if ($boolean_result) {
            watchdog('ldap_user', 'LDAP entry on server %sid deleted dn=%dn. username=%username, uid=%uid', $tokens, WATCHDOG_INFO);
          }
          else {
            watchdog('ldap_user', 'LDAP entry on server %sid not deleted because error. username=%username, uid=%uid', $tokens, WATCHDOG_ERROR);
          }
        }
        else {
          $boolean_result = FALSE;
        }
      }
    }
  }
  return $boolean_result;
}