From bf7a4bc7fcdda1e09b89adbdbd888dbdc847267b Mon Sep 17 00:00:00 2001 From: umherirrender Date: Sat, 2 Jun 2012 10:46:37 +0200 Subject: [PATCH] clean up User::getOptions a bit * use local vars for often used objects * move some lines near the code, which depends on it Change-Id: I7a4d4ba1350cca69a8f1c6d355002ee8fdd8f2bc --- includes/User.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/includes/User.php b/includes/User.php index 84f02afcc7..01407b1d8e 100644 --- a/includes/User.php +++ b/includes/User.php @@ -4041,13 +4041,9 @@ class User { protected function saveOptions() { global $wgAllowPrefChange; - $extuser = ExternalUser::newFromUser( $this ); - $this->loadOptions(); - $dbw = wfGetDB( DB_MASTER ); - - $insert_rows = array(); + // Not using getOptions(), to keep hidden preferences in database $saveOptions = $this->mOptions; // Allow hooks to abort, for instance to save to a global profile. @@ -4056,13 +4052,17 @@ class User { return; } + $extuser = ExternalUser::newFromUser( $this ); + $userId = $this->getId(); + $insert_rows = array(); foreach( $saveOptions as $key => $value ) { # Don't bother storing default values - if ( ( is_null( self::getDefaultOption( $key ) ) && - !( $value === false || is_null($value) ) ) || - $value != self::getDefaultOption( $key ) ) { + $defaultOption = self::getDefaultOption( $key ); + if ( ( is_null( $defaultOption ) && + !( $value === false || is_null( $value ) ) ) || + $value != $defaultOption ) { $insert_rows[] = array( - 'up_user' => $this->getId(), + 'up_user' => $userId, 'up_property' => $key, 'up_value' => $value, ); @@ -4079,7 +4079,8 @@ class User { } } - $dbw->delete( 'user_properties', array( 'up_user' => $this->getId() ), __METHOD__ ); + $dbw = wfGetDB( DB_MASTER ); + $dbw->delete( 'user_properties', array( 'up_user' => $userId ), __METHOD__ ); $dbw->insert( 'user_properties', $insert_rows, __METHOD__ ); } -- 2.20.1