MediaWiki  REL1_22
runBatchedQuery.php
Go to the documentation of this file.
00001 <?php
00026 require_once __DIR__ . '/Maintenance.php';
00027 
00033 class BatchedQueryRunner extends Maintenance {
00034     public function __construct() {
00035         parent::__construct();
00036         $this->mDescription = "Run a query repeatedly until it affects 0 rows, and wait for slaves in between.\n" .
00037                 "NOTE: You need to set a LIMIT clause yourself.";
00038     }
00039 
00040     public function execute() {
00041         if ( !$this->hasArg() ) {
00042             $this->error( "No query specified. Specify the query as a command line parameter.", true );
00043         }
00044 
00045         $query = $this->getArg();
00046         $n = 1;
00047         $dbw = wfGetDB( DB_MASTER );
00048         do {
00049             $this->output( "Batch $n: " );
00050             $n++;
00051             $dbw->query( $query, __METHOD__ );
00052             $affected = $dbw->affectedRows();
00053             $this->output( "$affected rows\n" );
00054             wfWaitForSlaves();
00055         } while ( $affected > 0 );
00056     }
00057 
00058     public function getDbType() {
00059         return Maintenance::DB_ADMIN;
00060     }
00061 }
00062 
00063 
00064 $maintClass = "BatchedQueryRunner";
00065 require_once RUN_MAINTENANCE_IF_MAIN;