MediaWiki
REL1_20
|
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 $query = $this->getArg(); 00045 $n = 1; 00046 $dbw = wfGetDB( DB_MASTER ); 00047 do { 00048 $this->output( "Batch $n: " ); 00049 $n++; 00050 $dbw->query( $query, __METHOD__ ); 00051 $affected = $dbw->affectedRows(); 00052 $this->output( "$affected rows\n" ); 00053 wfWaitForSlaves(); 00054 } while ( $affected > 0 ); 00055 } 00056 00057 public function getDbType() { 00058 return Maintenance::DB_ADMIN; 00059 } 00060 } 00061 00062 00063 $maintClass = "BatchedQueryRunner"; 00064 require_once( RUN_MAINTENANCE_IF_MAIN );