From 4e184445f2e83f767d7aafbcedc96e61d04af8a2 Mon Sep 17 00:00:00 2001 From: Marco Ferrante Date: Thu, 13 Jul 2017 10:08:52 +0200 Subject: [PATCH] MDL-59432 auth_db: add aliases to field mapping query This patch fixes an issue with mapping different internal fields to the same external field. --- auth/db/auth.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/auth/db/auth.php b/auth/db/auth.php index 5660978f4a5..7248947e62d 100644 --- a/auth/db/auth.php +++ b/auth/db/auth.php @@ -171,7 +171,7 @@ class auth_plugin_db extends auth_plugin_base { } /** - * Returns user attribute mappings between moodle and ldap. + * Returns user attribute mappings between moodle and the external database. * * @return array */ @@ -215,8 +215,12 @@ class auth_plugin_db extends auth_plugin_base { // If at least one field is mapped from external db, get that mapped data. if ($selectfields) { $select = array(); + $fieldcount = 0; foreach ($selectfields as $localname=>$externalname) { - $select[] = "$externalname"; + // Without aliasing, multiple occurrences of the same external + // name can coalesce in only occurrence in the result. + $select[] = "$externalname AS F".$fieldcount; + $fieldcount++; } $select = implode(', ', $select); $sql = "SELECT $select