}
protected function doDBUpdates() {
- global $wgActorTableSchemaMigrationStage;
-
$batchSize = $this->getBatchSize();
$db = $this->getDB( DB_MASTER );
if ( !$db->tableExists( 'log_search' ) ) {
}
$end = $db->selectField( 'logging', 'MAX(log_id)', '', __FUNCTION__ );
+ // This maintenance script is for updating pre-1.16 to 1.16. The target_author_id and
+ // target_author_ip relations it adds will later be migrated to target_author_actor by
+ // migrateActors.php. If the schema is already 1.34, we should have nothing to do.
+ if ( !$db->fieldExists( 'logging', 'log_user' ) ) {
+ $this->output(
+ "This does not appear to be an upgrade from MediaWiki pre-1.16 "
+ . "(logging.log_user does not exist).\n"
+ );
+ $this->output( "Nothing to do.\n" );
+
+ return true;
+ }
+
# Do remaining chunk
$end += $batchSize - 1;
$blockStart = $start;
'logging', [ 'log_id', 'log_type', 'log_action', 'log_params' ], $cond, __FUNCTION__
);
foreach ( $res as $row ) {
+ // RevisionDelete logs - revisions
if ( LogEventsList::typeAction( $row, $delTypes, 'revision' ) ) {
- // RevisionDelete logs - revisions
$params = LogPage::extractParams( $row->log_params );
// Param format: <urlparam> <item CSV> [<ofield> <nfield>]
if ( count( $params ) < 2 ) {
$log = new LogPage( $row->log_type );
// Add item relations...
$log->addRelations( $field, $items, $row->log_id );
- // Query item author relations...
+ // Determine what table to query...
$prefix = substr( $field, 0, strpos( $field, '_' ) ); // db prefix
if ( !isset( self::$tableMap[$prefix] ) ) {
continue; // bad row?
}
- $tables = [ self::$tableMap[$prefix] ];
- $fields = [];
- $joins = [];
- if ( $wgActorTableSchemaMigrationStage & SCHEMA_COMPAT_WRITE_OLD ) {
- // Read the old fields if we're still writing them regardless of read mode, to handle upgrades
- $fields['userid'] = $prefix . '_user';
- $fields['username'] = $prefix . '_user_text';
- }
- if ( $wgActorTableSchemaMigrationStage & SCHEMA_COMPAT_WRITE_NEW ) {
- // Read the new fields if we're writing them regardless of read mode, to handle upgrades
- if ( $prefix === 'rev' ) {
- $tables[] = 'revision_actor_temp';
- $joins['revision_actor_temp'] = [
- ( $wgActorTableSchemaMigrationStage & SCHEMA_COMPAT_WRITE_OLD ) ? 'LEFT JOIN' : 'JOIN',
- 'rev_id = revactor_rev',
- ];
- $fields['actorid'] = 'revactor_actor';
- } else {
- $fields['actorid'] = $prefix . '_actor';
+ $table = self::$tableMap[$prefix];
+ $userField = $prefix . '_user';
+ $userTextField = $prefix . '_user_text';
+ // Add item author relations...
+ $userIds = $userIPs = [];
+ $sres = $db->select( $table,
+ [ $userField, $userTextField ],
+ [ $field => $items ]
+ );
+ foreach ( $sres as $srow ) {
+ if ( $srow->$userField > 0 ) {
+ $userIds[] = intval( $srow->$userField );
+ } elseif ( $srow->$userTextField != '' ) {
+ $userIPs[] = $srow->$userTextField;
}
}
- $sres = $db->select( $tables, $fields, [ $field => $items ], __METHOD__, [], $joins );
+ // Add item author relations...
+ $log->addRelations( 'target_author_id', $userIds, $row->log_id );
+ $log->addRelations( 'target_author_ip', $userIPs, $row->log_id );
} elseif ( LogEventsList::typeAction( $row, $delTypes, 'event' ) ) {
// RevisionDelete logs - log events
$params = LogPage::extractParams( $row->log_params );
$log = new LogPage( $row->log_type );
// Add item relations...
$log->addRelations( 'log_id', $items, $row->log_id );
- // Query item author relations...
- $fields = [];
- if ( $wgActorTableSchemaMigrationStage & SCHEMA_COMPAT_WRITE_OLD ) {
- // Read the old fields if we're still writing them regardless of read mode, to handle upgrades
- $fields['userid'] = 'log_user';
- $fields['username'] = 'log_user_text';
- }
- if ( $wgActorTableSchemaMigrationStage & SCHEMA_COMPAT_WRITE_NEW ) {
- // Read the new fields if we're writing them regardless of read mode, to handle upgrades
- $fields['actorid'] = 'log_actor';
- }
-
- $sres = $db->select( 'logging', $fields, [ 'log_id' => $items ], __METHOD__ );
- } else {
- continue;
- }
-
- // Add item author relations...
- $userIds = $userIPs = $userActors = [];
- foreach ( $sres as $srow ) {
- if ( $wgActorTableSchemaMigrationStage & SCHEMA_COMPAT_WRITE_OLD ) {
- if ( $srow->userid > 0 ) {
- $userIds[] = intval( $srow->userid );
- } elseif ( $srow->username != '' ) {
- $userIPs[] = $srow->username;
+ // Add item author relations...
+ $userIds = $userIPs = [];
+ $sres = $db->select( 'logging',
+ [ 'log_user', 'log_user_text' ],
+ [ 'log_id' => $items ]
+ );
+ foreach ( $sres as $srow ) {
+ if ( $srow->log_user > 0 ) {
+ $userIds[] = intval( $srow->log_user );
+ } elseif ( IP::isIPAddress( $srow->log_user_text ) ) {
+ $userIPs[] = $srow->log_user_text;
}
}
- if ( $wgActorTableSchemaMigrationStage & SCHEMA_COMPAT_WRITE_NEW ) {
- if ( $srow->actorid ) {
- $userActors[] = intval( $srow->actorid );
- } elseif ( $srow->userid > 0 ) {
- $userActors[] = User::newFromId( $srow->userid )->getActorId( $db );
- } else {
- $userActors[] = User::newFromName( $srow->username, false )->getActorId( $db );
- }
- }
- }
- // Add item author relations...
- if ( $wgActorTableSchemaMigrationStage & SCHEMA_COMPAT_WRITE_OLD ) {
$log->addRelations( 'target_author_id', $userIds, $row->log_id );
$log->addRelations( 'target_author_ip', $userIPs, $row->log_id );
}
- if ( $wgActorTableSchemaMigrationStage & SCHEMA_COMPAT_WRITE_NEW ) {
- $log->addRelations( 'target_author_actor', $userActors, $row->log_id );
- }
}
$blockStart += $batchSize;
$blockEnd += $batchSize;