From f8aec598e07f7a154736bbb5f35de6befdafdd0e Mon Sep 17 00:00:00 2001 From: "Mark A. Hershberger" Date: Fri, 3 Jun 2011 01:06:07 +0000 Subject: [PATCH] =?utf8?q?Fix=20for=20bug=20#28172=20(=E2=80=9CwfGetDB=20c?= =?utf8?q?alled=20when=20it=20shouldn't=20be=E2=80=9D).?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit forward ported from r88936 and r89374. --- includes/User.php | 24 ++++++++++++------------ includes/installer/Installer.php | 18 ++++++++++++------ 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/includes/User.php b/includes/User.php index 2e4d569513..922f40f43a 100644 --- a/includes/User.php +++ b/includes/User.php @@ -2230,9 +2230,9 @@ class User { * This takes immediate effect. * @param $group String Name of the group to add */ - function addGroup( $group ) { + function addGroup( $group, $dbw = null ) { if( wfRunHooks( 'UserAddGroup', array( &$this, &$group ) ) ) { - $dbw = wfGetDB( DB_MASTER ); + if( $dbw == null ) $dbw = wfGetDB( DB_MASTER ); if( $this->getId() ) { $dbw->insert( 'user_groups', array( @@ -2603,14 +2603,14 @@ class User { * Save this user's settings into the database. * @todo Only rarely do all these fields need to be set! */ - function saveSettings() { + function saveSettings( $dbw = null ) { $this->load(); if ( wfReadOnly() ) { return; } if ( 0 == $this->mId ) { return; } $this->mTouched = self::newTouchedTimestamp(); - $dbw = wfGetDB( DB_MASTER ); + if( $dbw === null ) $dbw = wfGetDB( DB_MASTER ); $dbw->update( 'user', array( /* SET */ 'user_name' => $this->mName, @@ -2630,7 +2630,7 @@ class User { ), __METHOD__ ); - $this->saveOptions(); + $this->saveOptions( $dbw ); wfRunHooks( 'UserSaveSettings', array( $this ) ); $this->clearSharedCache(); @@ -2641,11 +2641,11 @@ class User { * If only this user's username is known, and it exists, return the user ID. * @return Int */ - function idForName() { + function idForName( $dbr = null ) { $s = trim( $this->getName() ); if ( $s === '' ) return 0; - $dbr = wfGetDB( DB_SLAVE ); + if( $dbr == null ) $dbr = wfGetDB( DB_SLAVE ); $id = $dbr->selectField( 'user', 'user_id', array( 'user_name' => $s ), __METHOD__ ); if ( $id === false ) { $id = 0; @@ -2708,9 +2708,9 @@ class User { /** * Add this existing user object to the database */ - function addToDatabase() { + function addToDatabase( $dbw = null ) { $this->load(); - $dbw = wfGetDB( DB_MASTER ); + if( $dbw === null ) $dbw = wfGetDB( DB_MASTER ); $seqVal = $dbw->nextSequenceValue( 'user_user_id_seq' ); $dbw->insert( 'user', array( @@ -2733,7 +2733,7 @@ class User { // Clear instance cache other than user table data, which is already accurate $this->clearInstanceCache(); - $this->saveOptions(); + $this->saveOptions( $dbw ); } /** @@ -3778,13 +3778,13 @@ class User { wfRunHooks( 'UserLoadOptions', array( $this, &$this->mOptions ) ); } - protected function saveOptions() { + protected function saveOptions( $dbw = null ) { global $wgAllowPrefChange; $extuser = ExternalUser::newFromUser( $this ); $this->loadOptions(); - $dbw = wfGetDB( DB_MASTER ); + if( $dbw === null ) $dbw = wfGetDB( DB_MASTER ); $insert_rows = array(); diff --git a/includes/installer/Installer.php b/includes/installer/Installer.php index 25449cef43..6df0e082cf 100644 --- a/includes/installer/Installer.php +++ b/includes/installer/Installer.php @@ -1407,14 +1407,20 @@ abstract class Installer { protected function createSysop() { $name = $this->getVar( '_AdminName' ); $user = User::newFromName( $name ); + $status = $this->getDBInstaller()->getConnection(); + if( $status->isOK() ) { + $db = $status->value; + } else { + return Status::newFatal( 'config-admin-error-user', $name ); + } if ( !$user ) { // We should've validated this earlier anyway! return Status::newFatal( 'config-admin-error-user', $name ); } - if ( $user->idForName() == 0 ) { - $user->addToDatabase(); + if ( $user->idForName( $db ) == 0 ) { + $user->addToDatabase( $db ); try { $user->setPassword( $this->getVar( '_AdminPassword' ) ); @@ -1422,12 +1428,12 @@ abstract class Installer { return Status::newFatal( 'config-admin-error-password', $name, $pwe->getMessage() ); } - $user->addGroup( 'sysop' ); - $user->addGroup( 'bureaucrat' ); + $user->addGroup( 'sysop', $db ); + $user->addGroup( 'bureaucrat', $db ); if( $this->getVar( '_AdminEmail' ) ) { $user->setEmail( $this->getVar( '_AdminEmail' ) ); } - $user->saveSettings(); + $user->saveSettings( $db ); // Update user count $ssUpdate = new SiteStatsUpdate( 0, 0, 0, 0, 1 ); @@ -1461,7 +1467,7 @@ abstract class Installer { array( 'method' => 'POST', 'postData' => $params ) )->execute(); if( !$res->isOK() ) { $s->warning( 'config-install-subscribe-fail', $res->getMessage() ); - } + } } /** -- 2.20.1