26require_once __DIR__ .
'/Maintenance.php';
37 parent::__construct();
39 "Run an update query on all rows of a table. " .
40 "Waits for replicas at appropriate intervals." );
41 $this->
addOption(
'table',
'The table name',
true,
true );
42 $this->
addOption(
'set',
'The SET clause',
true,
true );
43 $this->
addOption(
'where',
'The WHERE clause',
false,
true );
44 $this->
addOption(
'key',
'A column name, the values of which are unique',
true,
true );
45 $this->
addOption(
'batch-size',
'The batch size (default 1000)',
false,
true );
46 $this->
addOption(
'db',
'The database name, or omit to use the current wiki.',
false,
true );
53 $where = $this->
getOption(
'where',
null );
54 $where = $where ===
null ? [] : [ $where ];
55 $batchSize = $this->
getOption(
'batch-size', 1000 );
58 if ( $dbName ===
null ) {
61 $lbf = MediaWiki\MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
62 $lb = $lbf->getMainLB( $dbName );
63 $dbw = $lb->getConnection(
DB_MASTER, [], $dbName );
66 $selectConds = $where;
71 $this->
output(
"Batch $n: " );
80 $res = $dbw->select( $table, $key, $selectConds, __METHOD__,
81 [
'ORDER BY' => $key,
'LIMIT' => $batchSize ] );
82 if (
$res->numRows() ) {
84 $row =
$res->fetchObject();
85 $end = $dbw->addQuotes( $row->$key );
86 $selectConds = array_merge( $where, [
"$key > $end" ] );
87 $updateConds = array_merge( $where, [
"$key <= $end" ] );
89 $updateConds = $where;
91 if ( $prevEnd !==
false ) {
92 $updateConds = array_merge( [
"$key > $prevEnd" ], $updateConds );
95 $query =
"UPDATE " . $dbw->tableName( $table ) .
97 " WHERE " . $dbw->makeList( $updateConds, IDatabase::LIST_AND );
99 $dbw->query(
$query, __METHOD__ );
103 $affected = $dbw->affectedRows();
104 $this->
output(
"$affected rows affected\n" );
106 }
while (
$res->numRows() );
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
wfWaitForSlaves( $ifWritesSince=null, $wiki=false, $cluster=false, $timeout=null)
Waits for the replica DBs to catch up to the master position.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
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...
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
require_once RUN_MAINTENANCE_IF_MAIN