From f787f099544b8735cc51baa0fe49898bdf4c84dd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come@opensides.be>
Date: Thu, 22 Aug 2019 11:49:54 +0200
Subject: [PATCH] :ambulance: fix(setup) Fixed ldap parse_result call

We cannot pass arguments by reference through ldapMultiplexer

issue #2895
---
 include/class_ldap.inc           | 12 ++++++++----
 setup/class_setupStepMigrate.inc |  6 ++++--
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/include/class_ldap.inc b/include/class_ldap.inc
index 427be0ee3..397842db4 100644
--- a/include/class_ldap.inc
+++ b/include/class_ldap.inc
@@ -366,13 +366,17 @@ class LDAP
    * \param integer $srp srp
    *
    */
-  function parse_result ($srp, &$errcode, &$matcheddn, &$errmsg, &$referrals, &$controls): bool
+  function parse_result ($srp): array
   {
     if ($this->hascon && $this->hasres[$srp]) {
-      return @ldap_parse_result($this->cid, $this->sr[$srp], $errcode, $matcheddn, $errmsg, $referrals, $controls);
+      if (ldap_parse_result($this->cid, $this->sr[$srp], $errcode, $matcheddn, $errmsg, $referrals, $controls)) {
+        return [$errcode, $matcheddn, $errmsg, $referrals, $controls];
+      } else {
+        throw new FusionDirectoryException(_('Parsing LDAP result failed'));
+      }
+    } else {
+      throw new FusionDirectoryException(_('No LDAP result to parse'));
     }
-
-    return FALSE;
   }
 
   /*
diff --git a/setup/class_setupStepMigrate.inc b/setup/class_setupStepMigrate.inc
index c54ea9d6f..dc71532be 100644
--- a/setup/class_setupStepMigrate.inc
+++ b/setup/class_setupStepMigrate.inc
@@ -1011,10 +1011,12 @@ class setupStepMigrate extends setupStep
             _('Possibly the "root object" is missing.')
           );
         }
-        if (!$ldap->parse_result($errcode, $matcheddn, $errmsg, $referrals, $controls)) {
+        try {
+          list($errcode, $matcheddn, $errmsg, $referrals, $controls) = $ldap->parse_result();
+        } catch (FusionDirectoryException $e) {
           throw new CheckFailedException(
             _('LDAP result parsing failed'),
-            _('LDAP result parsing failed')
+            $e->getMessage()
           );
         }
         if ($errcode !== 0) {
-- 
GitLab