Skip to content

Commit

Permalink
Merge branch 'weirdgloop/REL1_41-reverted' into weirdgloop/REL1_41
Browse files Browse the repository at this point in the history
  • Loading branch information
TehKittyCat committed Apr 11, 2024
2 parents 6cff6b5 + 940fc2e commit 19dcdce
Show file tree
Hide file tree
Showing 50 changed files with 1,236 additions and 429 deletions.
16 changes: 5 additions & 11 deletions extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,6 @@
"value": 86400,
"description": "Number of seconds for which the temporary account API response is fresh"
},
"CheckUserCommentMigrationStage": {
"value": 259,
"description": "A flag used to represent the stage of the migration to the comment table. Default is to write to new and old, and read from old."
},
"CheckUserLogReasonMigrationStage": {
"value": 259,
"description": "A flag used to represent the stage of the migration to the comment table. Default is to write to new and old, and read from old."
},
"CheckUserEventTablesMigrationStage": {
"value": 259,
"description": "A flag used as the migration stage to the new cu_private_event and cu_log_event tables. Currently set to SCHEMA_COMPAT_OLD | SCHEMA_COMPAT_WRITE_NEW which evaluates to the integer 259."
Expand Down Expand Up @@ -180,13 +172,14 @@
"UserIdentityLookup",
"RevisionLookup",
"ArchivedRevisionLookup",
"CheckUserLogService"
"CheckUserLogService",
"CommentStore"
]
},
"checkuserlog": {
"class": "MediaWiki\\CheckUser\\Api\\ApiQueryCheckUserLog",
"services": [
"CheckUserLogCommentStore",
"CommentStore",
"CheckUserLogService",
"UserFactory"
]
Expand Down Expand Up @@ -523,6 +516,7 @@
"UserNameUtils",
"CheckUserHookRunner",
"CheckUserUtilityService",
"CommentStore",
"UserAgentClientHintsLookup",
"UserAgentClientHintsFormatter"
]
Expand All @@ -532,7 +526,7 @@
"services": [
"LinkBatchFactory",
"PermissionManager",
"CheckUserLogCommentStore",
"CommentStore",
"CommentFormatter",
"CheckUserLogService",
"UserFactory",
Expand Down
17 changes: 6 additions & 11 deletions maintenance/importCheckUserLogs.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php

use MediaWiki\CheckUser\CheckUserLogCommentStore;
use MediaWiki\CheckUser\Services\CheckUserLogService;
use MediaWiki\MediaWikiServices;
use MediaWiki\WikiMap\WikiMap;
Expand Down Expand Up @@ -104,11 +103,9 @@ protected function importLog( $file ) {

$services = MediaWikiServices::getInstance();
$userFactory = $services->getUserFactory();
/** @var CheckUserLogCommentStore $checkUserLogCommentStore */
$checkUserLogCommentStore = $services->get( 'CheckUserLogCommentStore' );
$commentStore = $services->getCommentStore();
/** @var CheckUserLogService $checkUserLogService */
$checkUserLogService = $services->get( 'CheckUserLogService' );
$culReasonMigrationStage = $services->getMainConfig()->get( 'CheckUserLogReasonMigrationStage' );

while ( !feof( $file ) ) {
$line = fgets( $file );
Expand Down Expand Up @@ -147,13 +144,11 @@ protected function importLog( $file ) {
'cul_range_start' => $start,
'cul_range_end' => $end
];
$fields += $checkUserLogCommentStore->insert( $dbw, 'cul_reason', $data['reason'] );
if ( $culReasonMigrationStage & SCHEMA_COMPAT_WRITE_NEW ) {
$fields += $checkUserLogCommentStore->insert(
$dbw, 'cul_reason_plaintext',
$checkUserLogService->getPlaintextReason( $data['reason'] )
);
}
$fields += $commentStore->insert( $dbw, 'cul_reason', $data['reason'] );
$fields += $commentStore->insert(
$dbw, 'cul_reason_plaintext',
$checkUserLogService->getPlaintextReason( $data['reason'] )
);
$dbw->newInsertQueryBuilder()
->table( 'cu_log' )
->row( $fields )
Expand Down
15 changes: 2 additions & 13 deletions maintenance/moveLogEntriesFromCuChanges.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,6 @@ private function moveLogEntriesFromCuChanges() {
"Moving log entries from cu_changes to cu_private_event with cuc_id from $start to $end.\n"
);

$commentMigrationStage = $services->getMainConfig()->get( 'CheckUserCommentMigrationStage' );
$commentStore = $services->getCommentStore();

while ( $blockStart <= $end ) {
$this->output( "...checking and moving log entries with cuc_id from $blockStart to $blockEnd\n" );
$res = $dbw->newSelectQueryBuilder()
Expand All @@ -107,7 +104,6 @@ private function moveLogEntriesFromCuChanges() {
'cuc_title',
'cuc_actor',
'cuc_actiontext',
'cuc_comment',
'cuc_comment_id',
'cuc_page_id',
'cuc_timestamp',
Expand All @@ -129,7 +125,7 @@ private function moveLogEntriesFromCuChanges() {
$batch = [];
$setOnlyForReadOldBatch = [];
foreach ( $res as $row ) {
$entry = [
$batch[] = [
'cupe_timestamp' => $row->cuc_timestamp,
'cupe_namespace' => $row->cuc_namespace,
'cupe_title' => $row->cuc_title,
Expand All @@ -138,21 +134,14 @@ private function moveLogEntriesFromCuChanges() {
'cupe_log_action' => 'migrated-cu_changes-log-event',
'cupe_log_type' => 'checkuser-private-event',
'cupe_params' => LogEntryBase::makeParamBlob( [ '4::actiontext' => $row->cuc_actiontext ] ),
'cupe_comment_id' => $row->cuc_comment_id,
'cupe_ip' => $row->cuc_ip,
'cupe_ip_hex' => $row->cuc_ip_hex,
'cupe_xff' => $row->cuc_xff,
'cupe_xff_hex' => $row->cuc_xff_hex,
'cupe_agent' => $row->cuc_agent,
'cupe_private' => $row->cuc_private
];

if ( $commentMigrationStage & SCHEMA_COMPAT_READ_NEW ) {
$entry['cupe_comment_id'] = $row->cuc_comment_id;
} else {
$entry['cupe_comment_id'] = $commentStore->createComment( $dbw, $row->cuc_comment )->id;
}

$batch[] = $entry;
$setOnlyForReadOldBatch[] = $row->cuc_id;
}
if ( count( $batch ) ) {
Expand Down
14 changes: 1 addition & 13 deletions maintenance/populateCheckUserTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use DatabaseLogEntry;
use LoggedUpdateMaintenance;
use MediaWiki\CheckUser\Hooks;
use MediaWiki\MediaWikiServices;
use RecentChange;
use Wikimedia\IPUtils;
Expand Down Expand Up @@ -90,12 +89,8 @@ protected function doDBUpdates() {

$services = MediaWikiServices::getInstance();
$lbFactory = $services->getDBLoadBalancerFactory();

$commentMigrationStage = $services->getMainConfig()->get( 'CheckUserCommentMigrationStage' );

$commentStore = $services->getCommentStore();
$rcQuery = RecentChange::getQueryInfo();
$contLang = $services->getContentLanguage();

while ( $blockStart <= $end ) {
$this->output( "...migrating rc_id from $blockStart to $blockEnd\n" );
Expand Down Expand Up @@ -155,6 +150,7 @@ protected function doDBUpdates() {
'cuc_namespace' => $row->rc_namespace,
'cuc_title' => $row->rc_title,
'cuc_actor' => $row->rc_actor,
'cuc_comment_id' => $comment->id,
'cuc_minor' => $row->rc_minor,
'cuc_page_id' => $row->rc_cur_id,
'cuc_this_oldid' => $row->rc_this_oldid,
Expand All @@ -164,14 +160,6 @@ protected function doDBUpdates() {
'cuc_ip_hex' => IPUtils::toHex( $row->rc_ip ),
'cuc_only_for_read_old' => 0,
];
if ( $commentMigrationStage & SCHEMA_COMPAT_WRITE_OLD ) {
$cuChangesRow['cuc_comment'] = $contLang->truncateForDatabase(
$comment->text, Hooks::TEXT_FIELD_LENGTH
);
}
if ( $commentMigrationStage & SCHEMA_COMPAT_WRITE_NEW ) {
$cuChangesRow['cuc_comment_id'] = $comment->id;
}
if (
$row->rc_type == RC_LOG &&
( $eventTablesMigrationStage & SCHEMA_COMPAT_WRITE_NEW )
Expand Down
21 changes: 19 additions & 2 deletions maintenance/populateCulComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
use LoggedUpdateMaintenance;
use MediaWiki\CheckUser\Services\CheckUserLogService;
use MediaWiki\MediaWikiServices;
use Psr\Log\NullLogger;
use Wikimedia\Services\NoSuchServiceException;

$IP = getenv( 'MW_INSTALL_PATH' );
if ( $IP === false ) {
Expand Down Expand Up @@ -63,8 +65,23 @@ protected function getUpdateKey() {
protected function doDBUpdates() {
$services = MediaWikiServices::getInstance();
$commentStore = $services->getCommentStore();
/** @var CheckUserLogService $checkUserLogService */
$checkUserLogService = $services->get( 'CheckUserLogService' );
try {
/** @var CheckUserLogService $checkUserLogService */
$checkUserLogService = $services->get( 'CheckUserLogService' );
} catch ( NoSuchServiceException $ex ) {
# CheckUser ServiceWiring files may not loaded until
# postDatabaseUpdateMaintenance is run.
# If this is the case, manually get the service.
$checkUserLogService = new CheckUserLogService(
$services->getDBLoadBalancerFactory(),
$services->getCommentStore(),
$services->getCommentFormatter(),
// No need to log as this maintenance script does not use any methods
// that use the logger.
new NullLogger(),
$services->getActorStore()
);
}
$mainLb = $services->getDBLoadBalancerFactory()->getMainLB();
$dbr = $mainLb->getConnection( DB_REPLICA, 'vslow' );
$dbw = $mainLb->getMaintenanceConnectionRef( DB_PRIMARY );
Expand Down
Loading

0 comments on commit 19dcdce

Please sign in to comment.