Commit df089016 authored by Aaron Wells's avatar Aaron Wells
Browse files

Better usage of the DML API

Bug1180194

Change-Id: Idfaad6ba9138eabc8e0efa4f72a5a3da224c7eab
parent 5e2f3e6d
...@@ -211,9 +211,8 @@ function changeauth_submit(Pieform $form, $values) { ...@@ -211,9 +211,8 @@ function changeauth_submit(Pieform $form, $values) {
if ($user->authinstance != $values['authinstance']) { if ($user->authinstance != $values['authinstance']) {
// Authinstance can be changed by institutional admins if both the // Authinstance can be changed by institutional admins if both the
// old and new authinstances belong to the admin's institutions // old and new authinstances belong to the admin's institutions
$authinst = get_records_select_assoc('auth_instance', 'id = ?', $authinst = get_field('auth_instance', 'institution', 'id', $user->authinstance);
array($user->authinstance)); if ($USER->get('admin') || $USER->is_institutional_admin($authinst)) {
if ($USER->get('admin') || $USER->is_institutional_admin($authinst[$user->authinstance]->institution)) {
// determine the current remoteusername // determine the current remoteusername
$current_remotename = get_field('auth_remote_user', 'remoteusername', $current_remotename = get_field('auth_remote_user', 'remoteusername',
'authinstance', $user->authinstance, 'localusr', $user->id); 'authinstance', $user->authinstance, 'localusr', $user->id);
...@@ -221,10 +220,7 @@ function changeauth_submit(Pieform $form, $values) { ...@@ -221,10 +220,7 @@ function changeauth_submit(Pieform $form, $values) {
$current_remotename = $user->username; $current_remotename = $user->username;
} }
// remove row if new authinstance row already exists to avoid doubleups // remove row if new authinstance row already exists to avoid doubleups
if ($remoteuserexists = get_records_select_assoc('auth_remote_user', 'localusr = ? AND authinstance = ?', delete_records('auth_remote_user', 'authinstance', $values['authinstance'], 'localusr', $user->id);
array($user->id, $values['authinstance']))) {
delete_records('auth_remote_user', 'authinstance', $values['authinstance'], 'localusr', $user->id);
}
insert_record('auth_remote_user', (object) array( insert_record('auth_remote_user', (object) array(
'authinstance' => $values['authinstance'], 'authinstance' => $values['authinstance'],
'remoteusername' => $current_remotename, 'remoteusername' => $current_remotename,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment