X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FpopulateLogSearch.php;h=589be48fa798932b225348b38084cc638732207a;hb=a5ea73070652d807afb780a5bd9c6614b5e5a872;hp=41c3bc94acdbb6ad4ede4f27fa16b6d002211dd2;hpb=630a39ce6b686872db84c2c2d022bb6c26bf23a8;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/populateLogSearch.php b/maintenance/populateLogSearch.php index 41c3bc94ac..589be48fa7 100644 --- a/maintenance/populateLogSearch.php +++ b/maintenance/populateLogSearch.php @@ -31,12 +31,12 @@ require_once __DIR__ . '/Maintenance.php'; * @ingroup Maintenance */ class PopulateLogSearch extends LoggedUpdateMaintenance { - private static $tableMap = array( + private static $tableMap = [ 'rev' => 'revision', 'fa' => 'filearchive', 'oi' => 'oldimage', 'ar' => 'archive' - ); + ]; public function __construct() { parent::__construct(); @@ -53,33 +53,38 @@ class PopulateLogSearch extends LoggedUpdateMaintenance { } protected function doDBUpdates() { + global $wgActorTableSchemaMigrationStage; + + $batchSize = $this->getBatchSize(); $db = $this->getDB( DB_MASTER ); if ( !$db->tableExists( 'log_search' ) ) { $this->error( "log_search does not exist" ); return false; } - $start = $db->selectField( 'logging', 'MIN(log_id)', false, __FUNCTION__ ); + $start = $db->selectField( 'logging', 'MIN(log_id)', '', __FUNCTION__ ); if ( !$start ) { $this->output( "Nothing to do.\n" ); return true; } - $end = $db->selectField( 'logging', 'MAX(log_id)', false, __FUNCTION__ ); + $end = $db->selectField( 'logging', 'MAX(log_id)', '', __FUNCTION__ ); # Do remaining chunk - $end += $this->mBatchSize - 1; + $end += $batchSize - 1; $blockStart = $start; - $blockEnd = $start + $this->mBatchSize - 1; + $blockEnd = $start + $batchSize - 1; - $delTypes = array( 'delete', 'suppress' ); // revisiondelete types + $delTypes = [ 'delete', 'suppress' ]; // revisiondelete types while ( $blockEnd <= $end ) { $this->output( "...doing log_id from $blockStart to $blockEnd\n" ); - $cond = "log_id BETWEEN $blockStart AND $blockEnd"; - $res = $db->select( 'logging', '*', $cond, __FUNCTION__ ); + $cond = "log_id BETWEEN " . (int)$blockStart . " AND " . (int)$blockEnd; + $res = $db->select( + '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 ) { @@ -96,38 +101,39 @@ class PopulateLogSearch extends LoggedUpdateMaintenance { } else { // Clean up the row... $db->update( 'logging', - array( 'log_params' => implode( ',', $params ) ), - array( 'log_id' => $row->log_id ) ); + [ 'log_params' => implode( ',', $params ) ], + [ 'log_id' => $row->log_id ] ); } } $items = explode( ',', $params[1] ); $log = new LogPage( $row->log_type ); // Add item relations... $log->addRelations( $field, $items, $row->log_id ); - // Determine what table to query... + // Query item author relations... $prefix = substr( $field, 0, strpos( $field, '_' ) ); // db prefix if ( !isset( self::$tableMap[$prefix] ) ) { continue; // bad row? } - $table = self::$tableMap[$prefix]; - $userField = $prefix . '_user'; - $userTextField = $prefix . '_user_text'; - // Add item author relations... - $userIds = $userIPs = array(); - $sres = $db->select( $table, - array( $userField, $userTextField ), - array( $field => $items ) - ); - foreach ( $sres as $srow ) { - if ( $srow->$userField > 0 ) { - $userIds[] = intval( $srow->$userField ); - } elseif ( $srow->$userTextField != '' ) { - $userIPs[] = $srow->$userTextField; + $tables = [ self::$tableMap[$prefix] ]; + $fields = []; + $joins = []; + if ( $wgActorTableSchemaMigrationStage < MIGRATION_NEW ) { + $fields['userid'] = $prefix . '_user'; + $fields['username'] = $prefix . '_user_text'; + } + if ( $wgActorTableSchemaMigrationStage > MIGRATION_OLD ) { + if ( $prefix === 'rev' ) { + $tables[] = 'revision_actor_temp'; + $joins['revision_actor_temp'] = [ + $wgActorTableSchemaMigrationStage === MIGRATION_NEW ? 'JOIN' : 'LEFT JOIN', + 'rev_id = revactor_rev', + ]; + $fields['actorid'] = 'revactor_actor'; + } else { + $fields['actorid'] = $prefix . '_actor'; } } - // Add item author relations... - $log->addRelations( 'target_author_id', $userIds, $row->log_id ); - $log->addRelations( 'target_author_ip', $userIPs, $row->log_id ); + $sres = $db->select( $tables, $fields, [ $field => $items ], __METHOD__, [], $joins ); } elseif ( LogEventsList::typeAction( $row, $delTypes, 'event' ) ) { // RevisionDelete logs - log events $params = LogPage::extractParams( $row->log_params ); @@ -139,25 +145,52 @@ class PopulateLogSearch extends LoggedUpdateMaintenance { $log = new LogPage( $row->log_type ); // Add item relations... $log->addRelations( 'log_id', $items, $row->log_id ); - // Add item author relations... - $userIds = $userIPs = array(); - $sres = $db->select( 'logging', - array( 'log_user', 'log_user_text' ), - array( '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; + // Query item author relations... + $fields = []; + if ( $wgActorTableSchemaMigrationStage < MIGRATION_NEW ) { + $fields['userid'] = 'log_user'; + $fields['username'] = 'log_user_text'; + } + if ( $wgActorTableSchemaMigrationStage > MIGRATION_OLD ) { + $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 < MIGRATION_NEW ) { + if ( $srow->userid > 0 ) { + $userIds[] = intval( $srow->userid ); + } elseif ( $srow->username != '' ) { + $userIPs[] = $srow->username; } } + if ( $wgActorTableSchemaMigrationStage > MIGRATION_OLD ) { + 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 <= MIGRATION_WRITE_BOTH ) { $log->addRelations( 'target_author_id', $userIds, $row->log_id ); $log->addRelations( 'target_author_ip', $userIPs, $row->log_id ); } + if ( $wgActorTableSchemaMigrationStage >= MIGRATION_WRITE_BOTH ) { + $log->addRelations( 'target_author_actor', $userActors, $row->log_id ); + } } - $blockStart += $this->mBatchSize; - $blockEnd += $this->mBatchSize; + $blockStart += $batchSize; + $blockEnd += $batchSize; wfWaitForSlaves(); } $this->output( "Done populating log_search table.\n" ); @@ -166,5 +199,5 @@ class PopulateLogSearch extends LoggedUpdateMaintenance { } } -$maintClass = "PopulateLogSearch"; +$maintClass = PopulateLogSearch::class; require_once RUN_MAINTENANCE_IF_MAIN;