From 185aeb06bb3148e230f3e26e02f8a1ae67ab3086 Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Sat, 26 Sep 2009 21:48:58 +1200 Subject: [PATCH] Don't write the user record every time a user connects via external auth. --- inc/auth-functions.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/inc/auth-functions.php b/inc/auth-functions.php index a66d56d8..9e9b2f3d 100644 --- a/inc/auth-functions.php +++ b/inc/auth-functions.php @@ -99,8 +99,27 @@ function UpdateUserFromExternal( &$usr ) { } $qry = new PgQuery("SELECT * FROM usr WHERE user_no = $usr->user_no;" ); - if ( $qry->Exec('Login',__LINE,__FILE__) && $qry->rows == 1 ) + if ( $qry->Exec('Login',__LINE,__FILE__) && $qry->rows == 1 ) { $type = "UPDATE"; + if ( $old = $qry->Fetch() ) { + $changes = false; + foreach( $usr AS $k => $v ) { + if ( $old->{$k} != $v ) { + $changes = true; + dbg_error_log("Login","User '%s' field '%s' changed from '%s' to '%s'", $usr->username, $k, $old->{$k}, $v ); + break; + } + } + if ( !$changes ) { + dbg_error_log("Login","No changes to user record for '%s' - leaving as-is.", $usr->username ); + if ( isset($usr->active) && $usr->active == 'f' ) return false; + return; // Normal case, if there are no changes + } + else { + dbg_error_log("Login","Changes to user record for '%s' - updating.", $usr->username ); + } + } + } else $type = "INSERT";