00001 <?php
00025 require_once( dirname(__FILE__) . '/Maintenance.php' );
00026
00027 class BatchedQueryRunner extends Maintenance {
00028 public function __construct() {
00029 parent::__construct();
00030 $this->mDescription = "Run a query repeatedly until it affects 0 rows, and wait for slaves in between.\n" .
00031 "NOTE: You need to set a LIMIT clause yourself.";
00032 $this->addOption( 'wait', "Wait for replication lag to go down to this value. Default: 5", false, true );
00033 }
00034
00035 public function execute() {
00036 if ( !$this->hasArg() )
00037 $this->error( "No query specified. Specify the query as a command line parameter.", true );
00038
00039 $query = $this->getArg();
00040 $wait = $this->getOption( 'wait', 5 );
00041 $n = 1;
00042 $dbw = wfGetDb( DB_MASTER );
00043 do {
00044 $this->output( "Batch $n: " );
00045 $n++;
00046 $dbw->query( $query );
00047 $affected = $dbw->affectedRows();
00048 $this->output( "$affected rows\n" );
00049 wfWaitForSlaves( $wait );
00050 } while ( $affected > 0 );
00051 }
00052
00053 public function getDbType() {
00054 return Maintenance::DB_ADMIN;
00055 }
00056 }
00057
00058
00059 $maintClass = "BatchedQueryRunner";
00060 require_once( DO_MAINTENANCE );