From 61fff6bb9d6e3f5b10f3da13959f988b6fb706e5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come@opensides.be>
Date: Thu, 25 Jul 2019 09:41:28 +0200
Subject: [PATCH] :ambulance: fix(templates) Fix PHP error when applying
 templates with unique condition

issue #6019
---
 include/class_templateHandling.inc | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/include/class_templateHandling.inc b/include/class_templateHandling.inc
index 1fb402128..4ec050d51 100644
--- a/include/class_templateHandling.inc
+++ b/include/class_templateHandling.inc
@@ -239,12 +239,15 @@ class templateHandling
       foreach ($generator as $value) {
         $filter = '('.ldap_escape_f($unique).'='.ldap_escape_f($value).')';
         $ldap->search($filter, ['dn']);
-        if (
-          ($ldap->count() == 0) ||
-          (($target !== NULL) && ($ldap->count() == 1) && ($ldap->getDN() == $target))
-          ) {
+        if ($ldap->count() == 0) {
           return $value;
         }
+        if (($target !== NULL) && ($ldap->count() == 1)) {
+          $attrs = $ldap->fetch();
+          if ($attrs['dn'] == $target) {
+            return $value;
+          }
+        }
       }
     }
 
-- 
GitLab