13require_once __DIR__ .
'/Maintenance.php';
25 parent::__construct();
27 "Run an update query on all rows of a table. " .
28 "Waits for replicas at appropriate intervals." );
29 $this->
addOption(
'table',
'The table name',
true,
true );
30 $this->
addOption(
'set',
'The SET clause',
true,
true );
31 $this->
addOption(
'where',
'The WHERE clause',
false,
true );
32 $this->
addOption(
'key',
'A column name, the values of which are unique',
true,
true );
33 $this->
addOption(
'batch-size',
'The batch size (default 1000)',
false,
true );
34 $this->
addOption(
'db',
'The database name, or omit to use the current wiki.',
false,
true );
41 $where = $this->
getOption(
'where',
null );
42 $where = $where ===
null ? [] : [ $where ];
43 $batchSize = $this->
getOption(
'batch-size', 1000 );
46 if ( $dbName ===
null ) {
49 $dbw = $this->
getServiceContainer()->getConnectionProvider()->getPrimaryDatabase( $dbName );
52 $queryBuilder = $dbw->newSelectQueryBuilder()
56 ->caller( __METHOD__ );
58 $iterator =
new BatchRowIterator( $dbw, $queryBuilder, $key, $batchSize );
59 foreach ( $iterator as $n => $batch ) {
60 $this->
output(
"Batch $n: " );
68 $firstRow = reset( $batch );
69 $lastRow = end( $batch );
71 $dbw->newUpdateQueryBuilder()
75 ->andWhere( $dbw->expr( $key,
'>=', $firstRow->$key ) )
76 ->andWhere( $dbw->expr( $key,
'<=', $lastRow->$key ) )
77 ->caller( __METHOD__ )
80 $affected = $dbw->affectedRows();
81 $this->
output(
"$affected rows affected\n" );
88 return Maintenance::DB_ADMIN;
94require_once RUN_MAINTENANCE_IF_MAIN;
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
waitForReplication()
Wait for replica DB servers to catch up.
getOption( $name, $default=null)
Get an option, or return the default.
getServiceContainer()
Returns the main service container.
getPrimaryDB(string|false $virtualDomain=false)
addDescription( $text)
Set the description text.
Maintenance script to run a database query in batches and wait for replica DBs.
__construct()
Default constructor.
execute()
Do the actual work.
getDbType()
Does the script need different DB access? By default, we give Maintenance scripts normal rights to th...