| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
require_once __DIR__ . '/Maintenance.php'; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
class MigrateRevisionCommentTemp extends LoggedUpdateMaintenance { |
| 33 |
public function __construct() { |
| 34 |
parent::__construct(); |
| 35 |
$this->addDescription( |
| 36 |
'Copy the data from the revision_comment_temp into the revision table' |
| 37 |
); |
| 38 |
$this->addOption( |
| 39 |
'sleep', |
| 40 |
'Sleep time (in seconds) between every batch. Default: 0', |
| 41 |
false, |
| 42 |
true |
| 43 |
); |
| 44 |
} |
| 45 |
|
| 46 |
protected function getUpdateKey() { |
| 47 |
return __CLASS__; |
| 48 |
} |
| 49 |
|
| 50 |
protected function doDBUpdates() { |
| 51 |
$batchSize = $this->getBatchSize(); |
| 52 |
|
| 53 |
$dbw = $this->getDB( DB_PRIMARY ); |
| 54 |
if ( !$dbw->fieldExists( 'revision', 'rev_comment_id', __METHOD__ ) ) { |
| 55 |
$this->output( "Run update.php to create rev_comment_id.\n" ); |
| 56 |
return false; |
| 57 |
} |
| 58 |
if ( !$dbw->tableExists( 'revision_comment_temp', __METHOD__ ) ) { |
| 59 |
$this->output( "revision_comment_temp does not exist, so nothing to do.\n" ); |
| 60 |
return true; |
| 61 |
} |
| 62 |
|
| 63 |
$this->output( "Merging the revision_comment_temp table into the revision table...\n" ); |
| 64 |
$conds = []; |
| 65 |
$updated = 0; |
| 66 |
$sleep = (int)$this->getOption( 'sleep', 0 ); |
| 67 |
while ( true ) { |
| 68 |
$res = $dbw->newSelectQueryBuilder() |
| 69 |
->select( [ 'rev_id', 'revcomment_comment_id' ] ) |
| 70 |
->from( 'revision' ) |
| 71 |
->join( 'revision_comment_temp', null, 'rev_id=revcomment_rev' ) |
| 72 |
->where( [ 'rev_comment_id' => 0 ] ) |
| 73 |
->andWhere( $conds ) |
| 74 |
->limit( $batchSize ) |
| 75 |
->orderBy( 'rev_id' ) |
| 76 |
->caller( __METHOD__ ) |
| 77 |
->fetchResultSet(); |
| 78 |
|
| 79 |
$numRows = $res->numRows(); |
| 80 |
|
| 81 |
$last = null; |
| 82 |
foreach ( $res as $row ) { |
| 83 |
$last = $row->rev_id; |
| 84 |
$dbw->newUpdateQueryBuilder() |
| 85 |
->update( 'revision' ) |
| 86 |
->set( [ 'rev_comment_id' => $row->revcomment_comment_id ] ) |
| 87 |
->where( [ 'rev_id' => $row->rev_id ] ) |
| 88 |
->caller( __METHOD__ )->execute(); |
| 89 |
$updated += $dbw->affectedRows(); |
| 90 |
} |
| 91 |
|
| 92 |
if ( $numRows < $batchSize ) { |
| 93 |
|
| 94 |
break; |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
$this->output( "... rev_id=$last, updated $updated\n" ); |
| 99 |
$conds = [ $dbw->expr( 'rev_id', '>', $last ) ]; |
| 100 |
|
| 101 |
|
| 102 |
$this->waitForReplication(); |
| 103 |
if ( $sleep > 0 ) { |
| 104 |
sleep( $sleep ); |
| 105 |
} |
| 106 |
} |
| 107 |
$this->output( |
| 108 |
"Completed merge of revision_comment_temp into the revision table, " |
| 109 |
. "$updated rows updated.\n" |
| 110 |
); |
| 111 |
return true; |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
$maintClass = MigrateRevisionCommentTemp::class; |
| 117 |
require_once RUN_MAINTENANCE_IF_MAIN; |
| 118 |
|