From 2606f19e6fd7a7abdc989445a56bcf6f61f7620d Mon Sep 17 00:00:00 2001
From: Hendrik Grahl <hendrik.grahl@namics.com>
Date: Tue, 17 May 2016 17:15:34 +0200
Subject: [PATCH] Fix legacy calls to uid

---
 ldap_servers/ldap_servers.module |  2 +-
 ldap_user/ldap_user.module       | 14 ++++----------
 2 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/ldap_servers/ldap_servers.module b/ldap_servers/ldap_servers.module
index 3b9c5cc..d566e97 100644
--- a/ldap_servers/ldap_servers.module
+++ b/ldap_servers/ldap_servers.module
@@ -561,7 +561,7 @@ function ldap_servers_binary($value) {
  */
 
 function ldap_servers_get_user_ldap_data($drupal_user, $id = NULL, $ldap_context = NULL) {
-  if (is_object($drupal_user) && property_exists($drupal_user, 'uid') && $authname = ldap_user_get_identifier_from_map($drupal_user->uid)) {
+  if (is_object($drupal_user) && property_exists($drupal_user, 'uid') && $authname = ldap_user_get_identifier_from_map($drupal_user->id())) {
     $drupal_username = $authname;
   }
   else {
diff --git a/ldap_user/ldap_user.module b/ldap_user/ldap_user.module
index efc130c..56982ff 100644
--- a/ldap_user/ldap_user.module
+++ b/ldap_user/ldap_user.module
@@ -585,7 +585,8 @@ function ldap_user_get_uid_from_map($identifier) {
  * Replaces the authmap table retired in Drupal 8
  */
 function ldap_user_get_identifier_from_map($uid) {
-  $authmap = \Drupal::service('externalauth.authmap')->getAuthdata($uid, 'ldap_user');
+  $authmap = \Drupal::service('externalauth.authmap');
+  $authmap->getAuthdata($uid, 'ldap_user');
   if ( property_exists($authmap, 'authname') ) {
     return $authmap->authname;
   }
@@ -792,15 +793,8 @@ function ldap_user_is_ldap_associated($account, $direction = NULL) {
     if (property_exists($account, 'ldap_user_current_dn') && !empty($account->ldap_user_current_dn['und'][0]['value'])) {
       $to_drupal_user = TRUE;
     }
-    elseif (isset($account->uid)) {
-      // @FIXME use methods as ldap_user_identities is deprecated.
-      $authmaps = db_query(
-        "SELECT aid, uid, module, identifier FROM {ldap_user_identities} WHERE uid = :uid AND module = :module",
-        array(
-          ':uid' => $account->uid,
-          ':module' => 'ldap_user'
-        )
-        )->fetchAllAssoc('aid',  PDO::FETCH_ASSOC);
+    elseif ($account->id()) {
+      $authmaps = ldap_user_get_identifier_from_map($account->id());
       $to_drupal_user = (boolean)(count($authmaps));
     }
   }
-- 
2.7.3

