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