Made sql.php except a "cluster" option and cleaned up the arguments.
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 21 Feb 2013 20:48:35 +0000 (12:48 -0800)
committerAntoine Musso <hashar@free.fr>
Thu, 21 Feb 2013 21:36:09 +0000 (22:36 +0100)
* 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
maintenance/sql.php

index 3afd4bf..8fccf3b 100644 (file)
@@ -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.
index 9b0b576..ef1ec54 100644 (file)
@@ -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 );
                        }