MediaWiki REL1_33
BatchRowUpdate.php
Go to the documentation of this file.
1<?php
2/*
3 * Ties together the batch update components to provide a composable
4 * method of batch updating rows in a database. To use create a class
5 * implementing the RowUpdateGenerator interface and configure the
6 * BatchRowIterator and BatchRowWriter for access to the correct table.
7 * The components will handle reading, writing, and waiting for replica DBs
8 * while the generator implementation handles generating update arrays
9 * for singular rows.
10 *
11 * Instantiate:
12 * $updater = new BatchRowUpdate(
13 * new BatchRowIterator( $dbr, 'some_table', 'primary_key_column', 500 ),
14 * new BatchRowWriter( $dbw, 'some_table', 'clusterName' ),
15 * new MyImplementationOfRowUpdateGenerator
16 * );
17 *
18 * Run:
19 * $updater->execute();
20 *
21 * An example maintenance script utilizing the BatchRowUpdate can be
22 * located in the Echo extension file maintenance/updateSchema.php
23 *
24 * This program is free software; you can redistribute it and/or modify
25 * it under the terms of the GNU General Public License as published by
26 * the Free Software Foundation; either version 2 of the License, or
27 * (at your option) any later version.
28 *
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
33 *
34 * You should have received a copy of the GNU General Public License along
35 * with this program; if not, write to the Free Software Foundation, Inc.,
36 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
37 * http://www.gnu.org/copyleft/gpl.html
38 *
39 * @file
40 * @ingroup Maintenance
41 */
47 protected $reader;
48
53 protected $writer;
54
59 protected $generator;
60
64 protected $output;
65
74 public function __construct(
76 ) {
77 $this->reader = $reader;
78 $this->writer = $writer;
79 $this->generator = $generator;
80 $this->output = function ( $text ) {
81 }; // nop
82 }
83
87 public function execute() {
88 foreach ( $this->reader as $rows ) {
89 $updates = [];
90 foreach ( $rows as $row ) {
91 $update = $this->generator->update( $row );
92 if ( $update ) {
93 $updates[] = [
94 'primaryKey' => $this->reader->extractPrimaryKeys( $row ),
95 'changes' => $update,
96 ];
97 }
98 }
99
100 if ( $updates ) {
101 $this->output( "Processing " . count( $updates ) . " rows\n" );
102 $this->writer->write( $updates );
103 }
104 }
105
106 $this->output( "Completed\n" );
107 }
108
116 public function setOutput( callable $output ) {
117 $this->output = $output;
118 }
119
125 protected function output( $text ) {
126 call_user_func( $this->output, $text );
127 }
128}
setOutput(callable $output)
Accepts a callable which will receive a single parameter containing string status updates.
__construct(BatchRowIterator $reader, BatchRowWriter $writer, RowUpdateGenerator $generator)
execute()
Runs the batch update process.
output( $text)
Write out a status update.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
An extension writer
Definition hooks.txt:51
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction $rows
Definition hooks.txt:2818
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
Definition injection.txt:37