You are here

function ldap_servers_update_8301 in Lightweight Directory Access Protocol (LDAP) 8.4

Same name and namespace in other branches
  1. 8.3 ldap_servers/ldap_servers.install \ldap_servers_update_8301()

Updates bind method to new value.

File

ldap_servers/ldap_servers.install, line 56

Code

function ldap_servers_update_8301() {

  /** @var \Drupal\Core\Entity\EntityStorageInterface $storage */
  $storage = \Drupal::service('entity_type.manager')
    ->getStorage('ldap_server');
  $servers = $storage
    ->getQuery()
    ->execute();

  /** @var \Drupal\ldap_servers\Entity\Server $server */
  foreach ($storage
    ->loadMultiple($servers) as $server) {
    $currentMethod = $server
      ->get('bind_method');
    if ($currentMethod == 1) {
      $server
        ->set('bind_method', 'service_account');
    }
    elseif ($currentMethod == 2) {
      $server
        ->set('bind_method', 'user');
    }
    elseif ($currentMethod == 3) {
      $server
        ->set('bind_method', 'anon');
    }
    elseif ($currentMethod == 4) {
      $server
        ->set('bind_method', 'anon_user');
    }
    $server
      ->save();
  }
}