Merge "Add .pipeline/ with dev image variant"
[lhc/web/wiklou.git] / maintenance / populateLogSearch.php
index e80b6f6..bb48151 100644 (file)
@@ -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: <urlparam> <item CSV> [<ofield> <nfield>]
                                        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;