diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2014-12-27 15:41:37 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2014-12-31 11:43:28 +0100 |
commit | c1f9b1f7b1b77776192048005dcc66dcf3df2bfb (patch) | |
tree | 2b38796e738dd74cb42ecd9bfd151803108386bc /maintenance/sql.php | |
parent | b88ab0086858470dd1f644e64cb4e4f62bb2be9b (diff) |
Update to MediaWiki 1.24.1
Diffstat (limited to 'maintenance/sql.php')
-rw-r--r-- | maintenance/sql.php | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/maintenance/sql.php b/maintenance/sql.php index a628b0bc..afa3ef72 100644 --- a/maintenance/sql.php +++ b/maintenance/sql.php @@ -34,15 +34,17 @@ class MwSql extends Maintenance { parent::__construct(); $this->mDescription = "Send SQL queries to a MediaWiki database"; $this->addOption( 'cluster', 'Use an external cluster by name', false, true ); + $this->addOption( 'wikidb', 'The database wiki ID to use if not the current one', false, true ); $this->addOption( 'slave', 'Use a slave server (either "any" or by name)', false, true ); } public function execute() { + $wiki = $this->getOption( 'wikidb' ) ?: false; // Get the appropriate load balancer (for this wiki) if ( $this->hasOption( 'cluster' ) ) { - $lb = wfGetLBFactory()->getExternalLB( $this->getOption( 'cluster' ) ); + $lb = wfGetLBFactory()->getExternalLB( $this->getOption( 'cluster' ), $wiki ); } else { - $lb = wfGetLB(); + $lb = wfGetLB( $wiki ); } // Figure out which server to use if ( $this->hasOption( 'slave' ) ) { @@ -51,7 +53,8 @@ class MwSql extends Maintenance { $index = DB_SLAVE; } else { $index = null; - for ( $i = 0; $i < $lb->getServerCount(); ++$i ) { + $serverCount = $lb->getServerCount(); + for ( $i = 0; $i < $serverCount; ++$i ) { if ( $lb->getServerName( $i ) === $server ) { $index = $i; break; @@ -65,9 +68,9 @@ class MwSql extends Maintenance { $index = DB_MASTER; } // Get a DB handle (with this wiki's DB selected) from the appropriate load balancer - $dbw = $lb->getConnection( $index ); - if ( $this->hasOption( 'slave' ) && $dbw->getLBInfo( 'master' ) !== null ) { - $this->error( "The server selected ({$dbw->getServer()}) is not a slave.", 1 ); + $db = $lb->getConnection( $index, array(), $wiki ); + if ( $this->hasOption( 'slave' ) && $db->getLBInfo( 'master' ) !== null ) { + $this->error( "The server selected ({$db->getServer()}) is not a slave.", 1 ); } if ( $this->hasArg( 0 ) ) { @@ -76,7 +79,7 @@ class MwSql extends Maintenance { $this->error( "Unable to open input file", true ); } - $error = $dbw->sourceStream( $file, false, array( $this, 'sqlPrintResult' ) ); + $error = $db->sourceStream( $file, false, array( $this, 'sqlPrintResult' ) ); if ( $error !== true ) { $this->error( $error, true ); } else { @@ -85,12 +88,12 @@ class MwSql extends Maintenance { } $useReadline = function_exists( 'readline_add_history' ) - && Maintenance::posix_isatty( 0 /*STDIN*/ ); + && Maintenance::posix_isatty( 0 /*STDIN*/ ); if ( $useReadline ) { global $IP; $historyFile = isset( $_ENV['HOME'] ) ? - "{$_ENV['HOME']}/.mwsql_history" : "$IP/maintenance/.mwsql_history"; + "{$_ENV['HOME']}/.mwsql_history" : "$IP/maintenance/.mwsql_history"; readline_read_history( $historyFile ); } @@ -102,7 +105,7 @@ class MwSql extends Maintenance { # User simply pressed return key continue; } - $done = $dbw->streamStatementEnd( $wholeLine, $line ); + $done = $db->streamStatementEnd( $wholeLine, $line ); $wholeLine .= $line; @@ -114,16 +117,16 @@ class MwSql extends Maintenance { if ( $useReadline ) { # Delimiter is eated by streamStatementEnd, we add it # up in the history (bug 37020) - readline_add_history( $wholeLine . $dbw->getDelimiter() ); + readline_add_history( $wholeLine . $db->getDelimiter() ); readline_write_history( $historyFile ); } try { - $res = $dbw->query( $wholeLine ); - $this->sqlPrintResult( $res, $dbw ); + $res = $db->query( $wholeLine ); + $this->sqlPrintResult( $res, $db ); $prompt = $newPrompt; $wholeLine = ''; } catch ( DBQueryError $e ) { - $doDie = ! Maintenance::posix_isatty( 0 ); + $doDie = !Maintenance::posix_isatty( 0 ); $this->error( $e, $doDie ); } } @@ -132,8 +135,8 @@ class MwSql extends Maintenance { /** * Print the results, callback for $db->sourceStream() - * @param $res ResultWrapper The results object - * @param $db DatabaseBase object + * @param ResultWrapper $res The results object + * @param DatabaseBase $db */ public function sqlPrintResult( $res, $db ) { if ( !$res ) { |