From: Brad Jorsch Date: Wed, 7 Aug 2019 21:24:47 +0000 (-0400) Subject: Revert actor changes to populateLogSearch.php X-Git-Tag: 1.34.0-rc.0~538^2 X-Git-Url: http://git.cyclocoop.org/?a=commitdiff_plain;h=c5044bc70e0396fb2a90f621ecfa177832c36175;p=lhc%2Fweb%2Fwiklou.git Revert actor changes to populateLogSearch.php In all the past patches, we missed the fact that this maintenance script is run as an upgrade from MW pre-1.16 to MW 1.16. It's apparently not intended to be run outside of the upgrade process. Thus, let's revert the changes that were made to the script in I8d825eb0 and I4764c1c7. Instead, the script need only detect that the pre-1.16 schema it's looking for doesn't exist anymore and bail out. Bug: T188327 Change-Id: I7e03b45ef6d43b9069f0399089ab06e136a89fbc --- diff --git a/maintenance/populateLogSearch.php b/maintenance/populateLogSearch.php index e80b6f6665..bb48151681 100644 --- a/maintenance/populateLogSearch.php +++ b/maintenance/populateLogSearch.php @@ -53,8 +53,6 @@ class PopulateLogSearch extends LoggedUpdateMaintenance { } protected function doDBUpdates() { - global $wgActorTableSchemaMigrationStage; - $batchSize = $this->getBatchSize(); $db = $this->getDB( DB_MASTER ); if ( !$db->tableExists( 'log_search' ) ) { @@ -70,6 +68,19 @@ class PopulateLogSearch extends LoggedUpdateMaintenance { } $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; @@ -83,8 +94,8 @@ class PopulateLogSearch extends LoggedUpdateMaintenance { '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: [ ] if ( count( $params ) < 2 ) { @@ -109,33 +120,30 @@ class PopulateLogSearch extends LoggedUpdateMaintenance { $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 ); @@ -147,51 +155,22 @@ class PopulateLogSearch extends LoggedUpdateMaintenance { $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;