From 7d939705ce9dfb48a73d392305950886b37e07a4 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Thu, 21 Feb 2013 12:48:35 -0800 Subject: [PATCH] Made sql.php except a "cluster" option and cleaned up the arguments. * This lets people choose to run the script on some external cluster instead of only the primary cluster for a given wiki ID. Change-Id: I6e8c10bc772d4a26c38f2ed8ae5787c8d130bd4c --- RELEASE-NOTES-1.21 | 2 ++ maintenance/sql.php | 14 ++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/RELEASE-NOTES-1.21 b/RELEASE-NOTES-1.21 index 3afd4bf50c..8fccf3b4b0 100644 --- a/RELEASE-NOTES-1.21 +++ b/RELEASE-NOTES-1.21 @@ -99,6 +99,8 @@ production. * WikiText now permits the use of WAI-ARIA's role="presentation" inside of html elements and tables. This allows presentational markup, especially tables. To be marked up as such. +* maintenance/sql.php learned the --cluster option. Let you run the script + on some external cluster instead of the primary cluster for a given wiki. === Bug fixes in 1.21 === * (bug 40353) SpecialDoubleRedirect should support interwiki redirects. diff --git a/maintenance/sql.php b/maintenance/sql.php index 9b0b576c65..ef1ec541fd 100644 --- a/maintenance/sql.php +++ b/maintenance/sql.php @@ -33,13 +33,19 @@ class MwSql extends Maintenance { public function __construct() { parent::__construct(); $this->mDescription = "Send SQL queries to a MediaWiki database"; + $this->addOption( 'cluster', 'Use an external cluster by name', false, true ); } public function execute() { - $dbw = wfGetDB( DB_MASTER ); - if ( $this->hasArg() ) { - $fileName = $this->getArg(); - $file = fopen( $fileName, 'r' ); + // Get a DB handle (with this wiki's DB select) from the appropriate load balancer + if ( $this->hasOption( 'cluster' ) ) { + $lb = wfGetLBFactory()->getExternalLB( $this->getOption( 'cluster' ) ); + $dbw = $lb->getConnection( DB_MASTER ); // master for external LB + } else { + $dbw = wfGetDB( DB_MASTER ); // master for primary LB for this wiki + } + if ( $this->hasArg( 0 ) ) { + $file = fopen( $this->getArg( 0 ), 'r' ); if ( !$file ) { $this->error( "Unable to open input file", true ); } -- 2.20.1