74 $needComments = $comments;
78 foreach ( $needComments as $need => $dummy ) {
79 $need = (string)$need;
82 'comment_hash' => CommentStore::hash( $need,
null ),
83 'comment_text' => $need,
91 [
'comment_id',
'comment_text' ],
94 'comment_data' =>
null,
98 foreach (
$res as $row ) {
99 $comments[$row->comment_text] = $row->comment_id;
100 unset( $needComments[$row->comment_text] );
103 if ( !$needComments ) {
109 array_map(
static function ( $v ) {
111 'comment_hash' => CommentStore::hash( $v,
null ),
112 'comment_text' => $v,
114 }, array_keys( $needComments ) ),
133 protected function migrate( $table, $primaryKey, $oldField ) {
135 if ( !$dbw->fieldExists( $table, $oldField, __METHOD__ ) ) {
136 $this->
output(
"No need to migrate $table.$oldField, field does not exist\n" );
140 $newField = $oldField .
'_id';
141 $primaryKey = (array)$primaryKey;
142 $pkFilter = array_fill_keys( $primaryKey,
true );
143 $this->
output(
"Beginning migration of $table.$oldField to $table.$newField\n" );
144 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
145 $lbFactory->waitForReplication();
154 array_merge( $primaryKey, [ $oldField ] ),
161 'ORDER BY' => $primaryKey,
165 if ( !
$res->numRows() ) {
171 foreach (
$res as $row ) {
172 $comments[$row->$oldField] = 0;
177 foreach (
$res as $row ) {
181 $newField => $comments[$row->$oldField],
184 array_intersect_key( (array)$row, $pkFilter ) + [
189 $countUpdated += $dbw->affectedRows();
195 for ( $i = count( $primaryKey ) - 1; $i >= 0; $i-- ) {
196 $field = $primaryKey[$i];
197 $prompt[] = $row->$field;
198 $value = $dbw->addQuotes( $row->$field );
199 if ( $next ===
'' ) {
200 $next =
"$field > $value";
202 $next =
"$field > $value OR $field = $value AND ($next)";
205 $prompt = implode(
' ', array_reverse( $prompt ) );
206 $this->
output(
"... $prompt\n" );
207 $lbFactory->waitForReplication();
211 "Completed migration, updated $countUpdated row(s) with $countComments new comment(s)\n"
230 protected function migrateToTemp( $table, $primaryKey, $oldField, $newPrimaryKey, $newField ) {
232 if ( !$dbw->fieldExists( $table, $oldField, __METHOD__ ) ) {
233 $this->
output(
"No need to migrate $table.$oldField, field does not exist\n" );
237 $newTable = $table .
'_comment_temp';
238 $this->
output(
"Beginning migration of $table.$oldField to $newTable.$newField\n" );
239 MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->waitForReplication();
248 [ $table, $newTable ],
249 [ $primaryKey, $oldField ],
250 [ $newPrimaryKey =>
null ] + $next,
253 'ORDER BY' => $primaryKey,
256 [ $newTable => [
'LEFT JOIN',
"{$primaryKey}={$newPrimaryKey}" ] ]
258 if ( !
$res->numRows() ) {
264 foreach (
$res as $row ) {
265 $comments[$row->$oldField] = 0;
272 foreach (
$res as $row ) {
274 $newPrimaryKey => $row->$primaryKey,
275 $newField => $comments[$row->$oldField]
277 $updates[] = $row->$primaryKey;
280 $dbw->insert( $newTable, $inserts, __METHOD__ );
281 $dbw->update( $table, [ $oldField =>
'' ], [ $primaryKey => $updates ], __METHOD__ );
282 $countUpdated += $dbw->affectedRows();
286 $next = [ $primaryKey .
' > ' . $dbw->addQuotes( $row->$primaryKey ) ];
287 $this->
output(
"... {$row->$primaryKey}\n" );
291 "Completed migration, updated $countUpdated row(s) with $countComments new comment(s)\n"