X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=maintenance%2FrunBatchedQuery.php;h=76340cdb3281bc00048946d197883218eaec05c5;hb=12238a3704e777f59625d18636c81b16657e6593;hp=555b7b96e0a7272bc28ecc32281f7c079b15e356;hpb=659778619cc12d156d3547834c0f90f407584104;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/runBatchedQuery.php b/maintenance/runBatchedQuery.php index 555b7b96e0..76340cdb32 100644 --- a/maintenance/runBatchedQuery.php +++ b/maintenance/runBatchedQuery.php @@ -19,34 +19,39 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * http://www.gnu.org/copyleft/gpl.html * + * @file * @ingroup Maintenance */ -require_once( dirname( __FILE__ ) . '/Maintenance.php' ); +require_once __DIR__ . '/Maintenance.php'; +/** + * Maintenance script to run a database query in batches and wait for slaves. + * + * @ingroup Maintenance + */ class BatchedQueryRunner extends Maintenance { public function __construct() { parent::__construct(); $this->mDescription = "Run a query repeatedly until it affects 0 rows, and wait for slaves in between.\n" . "NOTE: You need to set a LIMIT clause yourself."; - $this->addOption( 'wait', "Wait for replication lag to go down to this value. Default: 5", false, true ); } public function execute() { - if ( !$this->hasArg() ) + if ( !$this->hasArg() ) { $this->error( "No query specified. Specify the query as a command line parameter.", true ); - + } + $query = $this->getArg(); - $wait = $this->getOption( 'wait', 5 ); $n = 1; - $dbw = wfGetDb( DB_MASTER ); + $dbw = wfGetDB( DB_MASTER ); do { $this->output( "Batch $n: " ); $n++; - $dbw->query( $query ); + $dbw->query( $query, __METHOD__ ); $affected = $dbw->affectedRows(); $this->output( "$affected rows\n" ); - wfWaitForSlaves( $wait ); + wfWaitForSlaves(); } while ( $affected > 0 ); } @@ -55,6 +60,5 @@ class BatchedQueryRunner extends Maintenance { } } - $maintClass = "BatchedQueryRunner"; -require_once( DO_MAINTENANCE ); +require_once RUN_MAINTENANCE_IF_MAIN;