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.';
54 "...cannot update while \$wgCommentTableSchemaMigrationStage < MIGRATION_WRITE_NEW\n"
60 'revision',
'rev_id',
'rev_comment',
'revcomment_rev',
'revcomment_comment_id'
62 $this->
migrate(
'archive',
'ar_id',
'ar_comment' );
63 $this->
migrate(
'ipblocks',
'ipb_id',
'ipb_reason' );
65 'image',
'img_name',
'img_description',
'imgcomment_name',
'imgcomment_description_id'
67 $this->
migrate(
'oldimage', [
'oi_name',
'oi_timestamp' ],
'oi_description' );
68 $this->
migrate(
'filearchive',
'fa_id',
'fa_deleted_reason' );
69 $this->
migrate(
'filearchive',
'fa_id',
'fa_description' );
70 $this->
migrate(
'recentchanges',
'rc_id',
'rc_comment' );
71 $this->
migrate(
'logging',
'log_id',
'log_comment' );
72 $this->
migrate(
'protected_titles', [
'pt_namespace',
'pt_title' ],
'pt_reason' );
84 $needComments = $comments;
88 foreach ( $needComments as $need => $dummy ) {
91 'comment_hash' => CommentStore::hash( $need,
null ),
92 'comment_text' => $need,
100 [
'comment_id',
'comment_text' ],
103 'comment_data' =>
null,
107 foreach (
$res as $row ) {
108 $comments[$row->comment_text] = $row->comment_id;
109 unset( $needComments[$row->comment_text] );
112 if ( !$needComments ) {
118 array_map(
function ( $v ) {
120 'comment_hash' => CommentStore::hash( $v,
null ),
121 'comment_text' => $v,
123 }, array_keys( $needComments ) ),
142 protected function migrate( $table, $primaryKey, $oldField ) {
143 $newField = $oldField .
'_id';
144 $primaryKey = (
array)$primaryKey;
145 $pkFilter = array_flip( $primaryKey );
146 $this->
output(
"Beginning migration of $table.$oldField to $table.$newField\n" );
157 array_merge( $primaryKey, [ $oldField ] ),
164 'ORDER BY' => $primaryKey,
168 if ( !
$res->numRows() ) {
174 foreach (
$res as $row ) {
175 $comments[$row->$oldField] = 0;
180 foreach (
$res as $row ) {
184 $newField => $comments[$row->$oldField],
187 array_intersect_key( (array)$row, $pkFilter ) + [
192 $countUpdated += $dbw->affectedRows();
198 for ( $i = count( $primaryKey ) - 1; $i >= 0; $i-- ) {
199 $field = $primaryKey[$i];
200 $prompt[] = $row->$field;
201 $value = $dbw->addQuotes( $row->$field );
202 if ( $next ===
'' ) {
203 $next =
"$field > $value";
205 $next =
"$field > $value OR $field = $value AND ($next)";
208 $prompt = implode(
' ', array_reverse( $prompt ) );
209 $this->
output(
"... $prompt\n" );
214 "Completed migration, updated $countUpdated row(s) with $countComments new comment(s)\n"
233 protected function migrateToTemp( $table, $primaryKey, $oldField, $newPrimaryKey, $newField ) {
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"
int $wgCommentTableSchemaMigrationStage
Comment table schema migration stage.
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.
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.
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling output() to send it all. It could be easily changed to send incrementally if that becomes useful
the array() calling protocol came about after MediaWiki 1.4rc1.
const MIGRATION_WRITE_NEW
require_once RUN_MAINTENANCE_IF_MAIN