mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 08:55:15 +02:00
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 ;-)
This commit is contained in:
parent
4d8c087e02
commit
0f02788f70
@ -117,20 +117,34 @@ class auth_plugin_db {
|
||||
"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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user