Skip to content
Permalink
Browse files

auth/db/auth.php - fewer queries against the ext db

Previously sync script would query the ext db once for each field that
might be wanted (repeated for each user).  Changed to query once for each
user.

Originally by Peter Bulmer <peter.bulmer@catalyst.net.net>
Somewhat adapted by Martin Langhoff ;-)
  • Loading branch information
martinlanghoff
martinlanghoff committed Jan 16, 2007
1 parent 4d8c087 commit 0f02788f70cff1ed8f010fd9103ba6e545ed09f7
Showing with 26 additions and 12 deletions.
  1. +26 −12 auth/db/auth.php
@@ -117,20 +117,34 @@ function get_userinfo($username) {
"department", "address", "city", "country", "description",
"idnumber", "lang");
$result = array();
//Array to map local fieldnames we want, to external fieldnames
$selectfields = array();
foreach ($fields as $field) {
if ($this->config->{'field_map_' . $field}) {
if ($rs = $authdb->Execute("SELECT " . $this->config->{'field_map_' . $field} . " as myfield FROM {$this->config->table}
WHERE {$this->config->fielduser} = '$username'")) {
if ( $rs->RecordCount() == 1 ) {
if (!empty($CFG->unicodedb)) {
$result["$field"] = addslashes(stripslashes($rs->fields['myfield']));
} else {
$result["$field"] = addslashes(stripslashes(utf8_decode($rs->fields['myfield'])));
}
}
}
if (!empty($this->config->{'field_map_' . $field})) {
$selectfields[$field] = $this->config->{'field_map_' . $field};
}
}
$result = array();
//If at least one field is mapped from external db, get that mapped data:
if ($selectfields) {
$select = '';
foreach ($selectfields as $localname=>$externalname) {
$select .= ", $externalname AS $localname";
}
$select = 'SELECT ' . substr($select,1);
$sql = $select .
" FROM {$this->config->table}" .
" WHERE {$this->config->fielduser} = '$username'";
if ($rs = $authdb->Execute($sql)) {
if ( $rs->RecordCount() == 1 ) {
foreach ($selectfields as $localname=>$externalname) {
if (empty($CFG->unicodedb)) {
$rs->fields[$localname] = utf8_decode($rs->fields[$localname]);
}
$result[$localname] = addslashes(stripslashes($rs->fields[$localname]));
}
}
}
}
$authdb->Close();

0 comments on commit 0f02788

Please sign in to comment.
You can’t perform that action at this time.