* 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(
* 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,
), __METHOD__
);
- $this->saveOptions();
+ $this->saveOptions( $dbw );
wfRunHooks( 'UserSaveSettings', array( $this ) );
$this->clearSharedCache();
* 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;
/**
* 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(
// Clear instance cache other than user table data, which is already accurate
$this->clearInstanceCache();
- $this->saveOptions();
+ $this->saveOptions( $dbw );
}
/**
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();
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' ) );
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 );
array( 'method' => 'POST', 'postData' => $params ) )->execute();
if( !$res->isOK() ) {
$s->warning( 'config-install-subscribe-fail', $res->getMessage() );
- }
+ }
}
/**