Fix for bug #28172 (“wfGetDB called when it shouldn't be”).

forward ported from r88936 and r89374.
This commit is contained in:
Mark A. Hershberger 2011-06-03 01:06:07 +00:00
parent 439a38eca2
commit f8aec598e0
2 changed files with 24 additions and 18 deletions

View file

@ -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();

View file

@ -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() );
}
}
}
/**