26require_once __DIR__ .
'/Maintenance.php';
36 parent::__construct();
37 $this->
addDescription(
'Migrates comments from pre-1.30 columns to the \'comment\' table' );
46 return 'comments already migrated.';
51 'revision',
'rev_id',
'rev_comment',
'revcomment_rev',
'revcomment_comment_id'
53 $this->
migrate(
'archive',
'ar_id',
'ar_comment' );
54 $this->
migrate(
'ipblocks',
'ipb_id',
'ipb_reason' );
55 $this->
migrate(
'image',
'img_name',
'img_description' );
56 $this->
migrate(
'oldimage', [
'oi_name',
'oi_timestamp' ],
'oi_description' );
57 $this->
migrate(
'filearchive',
'fa_id',
'fa_deleted_reason' );
58 $this->
migrate(
'filearchive',
'fa_id',
'fa_description' );
59 $this->
migrate(
'recentchanges',
'rc_id',
'rc_comment' );
60 $this->
migrate(
'logging',
'log_id',
'log_comment' );
61 $this->
migrate(
'protected_titles', [
'pt_namespace',
'pt_title' ],
'pt_reason' );
73 $needComments = $comments;
77 foreach ( $needComments
as $need => $dummy ) {
80 'comment_hash' => CommentStore::hash( $need,
null ),
81 'comment_text' => $need,
89 [
'comment_id',
'comment_text' ],
92 'comment_data' =>
null,
97 $comments[$row->comment_text] = $row->comment_id;
98 unset( $needComments[$row->comment_text] );
101 if ( !$needComments ) {
107 array_map(
function ( $v ) {
109 'comment_hash' => CommentStore::hash( $v,
null ),
110 'comment_text' => $v,
112 }, array_keys( $needComments ) ),
131 protected function migrate( $table, $primaryKey, $oldField ) {
133 if ( !$dbw->fieldExists( $table, $oldField, __METHOD__ ) ) {
134 $this->
output(
"No need to migrate $table.$oldField, field does not exist\n" );
138 $newField = $oldField .
'_id';
139 $primaryKey = (
array)$primaryKey;
140 $pkFilter = array_flip( $primaryKey );
141 $this->
output(
"Beginning migration of $table.$oldField to $table.$newField\n" );
151 array_merge( $primaryKey, [ $oldField ] ),
158 'ORDER BY' => $primaryKey,
162 if ( !
$res->numRows() ) {
168 foreach (
$res as $row ) {
169 $comments[$row->$oldField] = 0;
174 foreach (
$res as $row ) {
178 $newField => $comments[$row->$oldField],
181 array_intersect_key( (
array)$row, $pkFilter ) + [
186 $countUpdated += $dbw->affectedRows();
192 for ( $i = count( $primaryKey ) - 1; $i >= 0; $i-- ) {
193 $field = $primaryKey[$i];
194 $prompt[] = $row->$field;
195 $value = $dbw->addQuotes( $row->$field );
196 if ( $next ===
'' ) {
197 $next =
"$field > $value";
199 $next =
"$field > $value OR $field = $value AND ($next)";
202 $prompt = implode(
' ', array_reverse( $prompt ) );
203 $this->
output(
"... $prompt\n" );
208 "Completed migration, updated $countUpdated row(s) with $countComments new comment(s)\n"
227 protected function migrateToTemp( $table, $primaryKey, $oldField, $newPrimaryKey, $newField ) {
229 if ( !$dbw->fieldExists( $table, $oldField, __METHOD__ ) ) {
230 $this->
output(
"No need to migrate $table.$oldField, field does not exist\n" );
234 $newTable = $table .
'_comment_temp';
235 $this->
output(
"Beginning migration of $table.$oldField to $newTable.$newField\n" );
245 [ $table, $newTable ],
246 [ $primaryKey, $oldField ],
247 [ $newPrimaryKey =>
null ] + $next,
250 'ORDER BY' => $primaryKey,
253 [ $newTable => [
'LEFT JOIN',
"{$primaryKey}={$newPrimaryKey}" ] ]
255 if ( !
$res->numRows() ) {
261 foreach (
$res as $row ) {
262 $comments[$row->$oldField] = 0;
269 foreach (
$res as $row ) {
271 $newPrimaryKey => $row->$primaryKey,
272 $newField => $comments[$row->$oldField]
274 $updates[] = $row->$primaryKey;
277 $dbw->insert( $newTable, $inserts, __METHOD__ );
278 $dbw->update( $table, [ $oldField =>
'' ], [ $primaryKey => $updates ], __METHOD__ );
279 $countUpdated += $dbw->affectedRows();
283 $next = [ $primaryKey .
' > ' . $dbw->addQuotes( $row->$primaryKey ) ];
284 $this->
output(
"... {$row->$primaryKey}\n" );
288 "Completed migration, updated $countUpdated row(s) with $countComments new comment(s)\n"
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.
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
beginTransaction(IDatabase $dbw, $fname)
Begin a transcation on a DB.
commitTransaction(IDatabase $dbw, $fname)
Commit the transcation on a DB handle and wait for replica DBs to catch up.
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.
getBatchSize()
Returns batch size.
addDescription( $text)
Set the description text.
setBatchSize( $s=0)
Set the batch size.
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
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
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))