mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-24 00:13:36 +00:00
FixTrailingWhitespaceIds: Don't crash on complex conflicts
Also, move output and waiting to the outer loop.
Bug: T356196
Change-Id: Ibb88bfe3fb14e53eef4837ce9e681cebce399be1
(cherry picked from commit f4e419b019
)
This commit is contained in:
parent
5b415eb241
commit
fd87509978
|
@ -3,6 +3,7 @@
|
||||||
namespace MediaWiki\Extension\DiscussionTools\Maintenance;
|
namespace MediaWiki\Extension\DiscussionTools\Maintenance;
|
||||||
|
|
||||||
use LoggedUpdateMaintenance;
|
use LoggedUpdateMaintenance;
|
||||||
|
use Wikimedia\Rdbms\DBQueryError;
|
||||||
use Wikimedia\Rdbms\IDatabase;
|
use Wikimedia\Rdbms\IDatabase;
|
||||||
use Wikimedia\Rdbms\IExpression;
|
use Wikimedia\Rdbms\IExpression;
|
||||||
use Wikimedia\Rdbms\LikeValue;
|
use Wikimedia\Rdbms\LikeValue;
|
||||||
|
@ -73,6 +74,7 @@ class FixTrailingWhitespaceIds extends LoggedUpdateMaintenance {
|
||||||
if ( !$itemIds ) {
|
if ( !$itemIds ) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ( $itemIds as $itemId ) {
|
foreach ( $itemIds as $itemId ) {
|
||||||
$fixedItemId = preg_replace(
|
$fixedItemId = preg_replace(
|
||||||
'/^([hc]\-.*)_(\-([0-9]{14}|[0-9-]{10}T[0-9:]{6}00.000Z))?$/',
|
'/^([hc]\-.*)_(\-([0-9]{14}|[0-9-]{10}T[0-9:]{6}00.000Z))?$/',
|
||||||
|
@ -83,16 +85,26 @@ class FixTrailingWhitespaceIds extends LoggedUpdateMaintenance {
|
||||||
// In the rare case we got a false positive from the LIKE, add this to a list of skipped IDs
|
// In the rare case we got a false positive from the LIKE, add this to a list of skipped IDs
|
||||||
// so we don't keep selecting it, and end up in an infinite loop
|
// so we don't keep selecting it, and end up in an infinite loop
|
||||||
$skippedIds[] = $itemId;
|
$skippedIds[] = $itemId;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
$dbw->newUpdateQueryBuilder()
|
try {
|
||||||
->update( 'discussiontools_item_ids' )
|
$dbw->newUpdateQueryBuilder()
|
||||||
->set( [ 'itid_itemid' => $fixedItemId ] )
|
->update( 'discussiontools_item_ids' )
|
||||||
->where( [ 'itid_itemid' => $itemId ] )
|
->set( [ 'itid_itemid' => $fixedItemId ] )
|
||||||
->caller( __METHOD__ )->execute();
|
->where( [ 'itid_itemid' => $itemId ] )
|
||||||
$this->waitForReplication();
|
->caller( __METHOD__ )->execute();
|
||||||
|
} catch ( DBQueryError $err ) {
|
||||||
|
// Give up on updating in case of complex conflicts (T356196#9913698)
|
||||||
|
$this->output( "Failed to update $itemId\n" );
|
||||||
|
$skippedIds[] = $itemId;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$total += $dbw->affectedRows();
|
$total += $dbw->affectedRows();
|
||||||
$this->output( "$total\n" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->waitForReplication();
|
||||||
|
$this->output( "$total\n" );
|
||||||
} while ( true );
|
} while ( true );
|
||||||
|
|
||||||
$this->output( "Fixing DiscussionTools IDs with trailing whitespace: done.\n" );
|
$this->output( "Fixing DiscussionTools IDs with trailing whitespace: done.\n" );
|
||||||
|
|
Loading…
Reference in a new issue