X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FmigrateComments.php;h=8025df1f672b21733971aac0a49f3e702f19a4e1;hb=b3e4a6f61f314b0933832bc944551866da31773e;hp=9d4e2615c0c981779ddd216f7f5e1e02d9e8c28a;hpb=7e105610397b55d67f42f31496e92496477500e3;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/migrateComments.php b/maintenance/migrateComments.php index 9d4e2615c0..8025df1f67 100644 --- a/maintenance/migrateComments.php +++ b/maintenance/migrateComments.php @@ -47,23 +47,12 @@ class MigrateComments extends LoggedUpdateMaintenance { } protected function doDBUpdates() { - global $wgCommentTableSchemaMigrationStage; - - if ( $wgCommentTableSchemaMigrationStage < MIGRATION_WRITE_NEW ) { - $this->output( - "...cannot update while \$wgCommentTableSchemaMigrationStage < MIGRATION_WRITE_NEW\n" - ); - return false; - } - $this->migrateToTemp( 'revision', 'rev_id', 'rev_comment', 'revcomment_rev', 'revcomment_comment_id' ); $this->migrate( 'archive', 'ar_id', 'ar_comment' ); $this->migrate( 'ipblocks', 'ipb_id', 'ipb_reason' ); - $this->migrateToTemp( - 'image', 'img_name', 'img_description', 'imgcomment_name', 'imgcomment_description_id' - ); + $this->migrate( 'image', 'img_name', 'img_description' ); $this->migrate( 'oldimage', [ 'oi_name', 'oi_timestamp' ], 'oi_description' ); $this->migrate( 'filearchive', 'fa_id', 'fa_deleted_reason' ); $this->migrate( 'filearchive', 'fa_id', 'fa_description' ); @@ -140,12 +129,18 @@ class MigrateComments extends LoggedUpdateMaintenance { * @param string $oldField Old comment field name */ protected function migrate( $table, $primaryKey, $oldField ) { + $dbw = $this->getDB( DB_MASTER ); + if ( !$dbw->fieldExists( $table, $oldField, __METHOD__ ) ) { + $this->output( "No need to migrate $table.$oldField, field does not exist\n" ); + return; + } + $newField = $oldField . '_id'; $primaryKey = (array)$primaryKey; $pkFilter = array_flip( $primaryKey ); $this->output( "Beginning migration of $table.$oldField to $table.$newField\n" ); + wfWaitForSlaves(); - $dbw = $this->getDB( DB_MASTER ); $next = '1=1'; $countUpdated = 0; $countComments = 0; @@ -161,7 +156,7 @@ class MigrateComments extends LoggedUpdateMaintenance { __METHOD__, [ 'ORDER BY' => $primaryKey, - 'LIMIT' => $this->mBatchSize, + 'LIMIT' => $this->getBatchSize(), ] ); if ( !$res->numRows() ) { @@ -204,8 +199,9 @@ class MigrateComments extends LoggedUpdateMaintenance { $next = "$field > $value OR $field = $value AND ($next)"; } } - $prompt = join( ' ', array_reverse( $prompt ) ); + $prompt = implode( ' ', array_reverse( $prompt ) ); $this->output( "... $prompt\n" ); + wfWaitForSlaves(); } $this->output( @@ -229,8 +225,15 @@ class MigrateComments extends LoggedUpdateMaintenance { * @param string $newField New comment field name */ protected function migrateToTemp( $table, $primaryKey, $oldField, $newPrimaryKey, $newField ) { + $dbw = $this->getDB( DB_MASTER ); + if ( !$dbw->fieldExists( $table, $oldField, __METHOD__ ) ) { + $this->output( "No need to migrate $table.$oldField, field does not exist\n" ); + return; + } + $newTable = $table . '_comment_temp'; $this->output( "Beginning migration of $table.$oldField to $newTable.$newField\n" ); + wfWaitForSlaves(); $dbw = $this->getDB( DB_MASTER ); $next = []; @@ -245,7 +248,7 @@ class MigrateComments extends LoggedUpdateMaintenance { __METHOD__, [ 'ORDER BY' => $primaryKey, - 'LIMIT' => $this->mBatchSize, + 'LIMIT' => $this->getBatchSize(), ], [ $newTable => [ 'LEFT JOIN', "{$primaryKey}={$newPrimaryKey}" ] ] ); @@ -287,5 +290,5 @@ class MigrateComments extends LoggedUpdateMaintenance { } } -$maintClass = "MigrateComments"; +$maintClass = MigrateComments::class; require_once RUN_MAINTENANCE_IF_MAIN;