Skip to content

Commit

Permalink
MDL-59432 auth_db: add aliases to field mapping query
Browse files Browse the repository at this point in the history
This patch fixes an issue with mapping different internal fields
to the same external field.
  • Loading branch information
mfprimo authored and lameze committed Jul 20, 2017
1 parent 8e43414 commit d7360d7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions auth/db/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ function db_init() {
}

/**
* Returns user attribute mappings between moodle and ldap.
* Returns user attribute mappings between moodle and the external database.
*
* @return array
*/
Expand Down Expand Up @@ -215,8 +215,12 @@ function get_userinfo($username) {
// 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
Expand Down

0 comments on commit d7360d7

Please sign in to comment.