MediaWiki
REL1_19
|
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 } 00033 00034 public function execute() { 00035 if ( !$this->hasArg() ) 00036 $this->error( "No query specified. Specify the query as a command line parameter.", true ); 00037 00038 $query = $this->getArg(); 00039 $n = 1; 00040 $dbw = wfGetDB( DB_MASTER ); 00041 do { 00042 $this->output( "Batch $n: " ); 00043 $n++; 00044 $dbw->query( $query, __METHOD__ ); 00045 $affected = $dbw->affectedRows(); 00046 $this->output( "$affected rows\n" ); 00047 wfWaitForSlaves(); 00048 } while ( $affected > 0 ); 00049 } 00050 00051 public function getDbType() { 00052 return Maintenance::DB_ADMIN; 00053 } 00054 } 00055 00056 00057 $maintClass = "BatchedQueryRunner"; 00058 require_once( RUN_MAINTENANCE_IF_MAIN );