r89376 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89375‎ | r89376 | r89377 >
Date:01:06, 3 June 2011
Author:mah
Status:reverted (Comments)
Tags:
Comment:
Fix for bug #28172 (“wfGetDB called when it shouldn't be”).

forward ported from r88936 and r89374.
Modified paths:
  • /trunk/phase3/includes/User.php (modified) (history)
  • /trunk/phase3/includes/installer/Installer.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/User.php
@@ -2230,9 +2230,9 @@
22312231 * This takes immediate effect.
22322232 * @param $group String Name of the group to add
22332233 */
2234 - function addGroup( $group ) {
 2234+ function addGroup( $group, $dbw = null ) {
22352235 if( wfRunHooks( 'UserAddGroup', array( &$this, &$group ) ) ) {
2236 - $dbw = wfGetDB( DB_MASTER );
 2236+ if( $dbw == null ) $dbw = wfGetDB( DB_MASTER );
22372237 if( $this->getId() ) {
22382238 $dbw->insert( 'user_groups',
22392239 array(
@@ -2603,14 +2603,14 @@
26042604 * Save this user's settings into the database.
26052605 * @todo Only rarely do all these fields need to be set!
26062606 */
2607 - function saveSettings() {
 2607+ function saveSettings( $dbw = null ) {
26082608 $this->load();
26092609 if ( wfReadOnly() ) { return; }
26102610 if ( 0 == $this->mId ) { return; }
26112611
26122612 $this->mTouched = self::newTouchedTimestamp();
26132613
2614 - $dbw = wfGetDB( DB_MASTER );
 2614+ if( $dbw === null ) $dbw = wfGetDB( DB_MASTER );
26152615 $dbw->update( 'user',
26162616 array( /* SET */
26172617 'user_name' => $this->mName,
@@ -2630,7 +2630,7 @@
26312631 ), __METHOD__
26322632 );
26332633
2634 - $this->saveOptions();
 2634+ $this->saveOptions( $dbw );
26352635
26362636 wfRunHooks( 'UserSaveSettings', array( $this ) );
26372637 $this->clearSharedCache();
@@ -2641,11 +2641,11 @@
26422642 * If only this user's username is known, and it exists, return the user ID.
26432643 * @return Int
26442644 */
2645 - function idForName() {
 2645+ function idForName( $dbr = null ) {
26462646 $s = trim( $this->getName() );
26472647 if ( $s === '' ) return 0;
26482648
2649 - $dbr = wfGetDB( DB_SLAVE );
 2649+ if( $dbr == null ) $dbr = wfGetDB( DB_SLAVE );
26502650 $id = $dbr->selectField( 'user', 'user_id', array( 'user_name' => $s ), __METHOD__ );
26512651 if ( $id === false ) {
26522652 $id = 0;
@@ -2708,9 +2708,9 @@
27092709 /**
27102710 * Add this existing user object to the database
27112711 */
2712 - function addToDatabase() {
 2712+ function addToDatabase( $dbw = null ) {
27132713 $this->load();
2714 - $dbw = wfGetDB( DB_MASTER );
 2714+ if( $dbw === null ) $dbw = wfGetDB( DB_MASTER );
27152715 $seqVal = $dbw->nextSequenceValue( 'user_user_id_seq' );
27162716 $dbw->insert( 'user',
27172717 array(
@@ -2733,7 +2733,7 @@
27342734 // Clear instance cache other than user table data, which is already accurate
27352735 $this->clearInstanceCache();
27362736
2737 - $this->saveOptions();
 2737+ $this->saveOptions( $dbw );
27382738 }
27392739
27402740 /**
@@ -3778,13 +3778,13 @@
37793779 wfRunHooks( 'UserLoadOptions', array( $this, &$this->mOptions ) );
37803780 }
37813781
3782 - protected function saveOptions() {
 3782+ protected function saveOptions( $dbw = null ) {
37833783 global $wgAllowPrefChange;
37843784
37853785 $extuser = ExternalUser::newFromUser( $this );
37863786
37873787 $this->loadOptions();
3788 - $dbw = wfGetDB( DB_MASTER );
 3788+ if( $dbw === null ) $dbw = wfGetDB( DB_MASTER );
37893789
37903790 $insert_rows = array();
37913791
Index: trunk/phase3/includes/installer/Installer.php
@@ -1407,14 +1407,20 @@
14081408 protected function createSysop() {
14091409 $name = $this->getVar( '_AdminName' );
14101410 $user = User::newFromName( $name );
 1411+ $status = $this->getDBInstaller()->getConnection();
 1412+ if( $status->isOK() ) {
 1413+ $db = $status->value;
 1414+ } else {
 1415+ return Status::newFatal( 'config-admin-error-user', $name );
 1416+ }
14111417
14121418 if ( !$user ) {
14131419 // We should've validated this earlier anyway!
14141420 return Status::newFatal( 'config-admin-error-user', $name );
14151421 }
14161422
1417 - if ( $user->idForName() == 0 ) {
1418 - $user->addToDatabase();
 1423+ if ( $user->idForName( $db ) == 0 ) {
 1424+ $user->addToDatabase( $db );
14191425
14201426 try {
14211427 $user->setPassword( $this->getVar( '_AdminPassword' ) );
@@ -1422,12 +1428,12 @@
14231429 return Status::newFatal( 'config-admin-error-password', $name, $pwe->getMessage() );
14241430 }
14251431
1426 - $user->addGroup( 'sysop' );
1427 - $user->addGroup( 'bureaucrat' );
 1432+ $user->addGroup( 'sysop', $db );
 1433+ $user->addGroup( 'bureaucrat', $db );
14281434 if( $this->getVar( '_AdminEmail' ) ) {
14291435 $user->setEmail( $this->getVar( '_AdminEmail' ) );
14301436 }
1431 - $user->saveSettings();
 1437+ $user->saveSettings( $db );
14321438
14331439 // Update user count
14341440 $ssUpdate = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
@@ -1461,7 +1467,7 @@
14621468 array( 'method' => 'POST', 'postData' => $params ) )->execute();
14631469 if( !$res->isOK() ) {
14641470 $s->warning( 'config-install-subscribe-fail', $res->getMessage() );
1465 - }
 1471+ }
14661472 }
14671473
14681474 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r89738Revert r89374, r88936 backports.mah20:04, 8 June 2011
r101880Bug 28172 - wfGetDB called when it shouldn't beoverlordq21:00, 3 November 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r88936This needs to be forward-ported to trunk....mah21:49, 26 May 2011
r89374Finish fix for bug #28172 (“wfGetDB called when it shouldn't be”)....mah00:53, 3 June 2011

Comments

#Comment by Hashar (talk | contribs)   12:08, 3 June 2011

marking for 1.18.

#Comment by 😂 (talk | contribs)   18:55, 19 July 2011

This was reverted in r89738.

Status & tagging log