60 if ( !$db->tableExists(
'log_search', __METHOD__ ) ) {
61 $this->
error(
"log_search does not exist" );
65 $start = $db->selectField(
'logging',
'MIN(log_id)',
'', __FUNCTION__ );
67 $this->
output(
"Nothing to do.\n" );
71 $end = $db->selectField(
'logging',
'MAX(log_id)',
'', __FUNCTION__ );
76 if ( !$db->fieldExists(
'logging',
'log_user', __METHOD__ ) ) {
78 "This does not appear to be an upgrade from MediaWiki pre-1.16 "
79 .
"(logging.log_user does not exist).\n"
81 $this->
output(
"Nothing to do.\n" );
87 $end += $batchSize - 1;
89 $blockEnd = $start + $batchSize - 1;
90 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
92 $delTypes = [
'delete',
'suppress' ];
93 while ( $blockEnd <= $end ) {
94 $this->
output(
"...doing log_id from $blockStart to $blockEnd\n" );
95 $cond =
"log_id BETWEEN " . (int)$blockStart .
" AND " . (
int)$blockEnd;
97 'logging', [
'log_id',
'log_type',
'log_action',
'log_params' ], $cond, __FUNCTION__
99 foreach (
$res as $row ) {
101 if ( LogEventsList::typeAction( $row, $delTypes,
'revision' ) ) {
104 if ( count( $params ) < 2 ) {
109 if ( $field ==
null ) {
110 array_shift( $params );
112 if ( $field ==
null ) {
113 $this->
output(
"Invalid param type for {$row->log_id}\n" );
117 $db->update(
'logging',
118 [
'log_params' => implode(
',', $params ) ],
119 [
'log_id' => $row->log_id ],
124 $items = explode(
',', $params[1] );
125 $log =
new LogPage( $row->log_type );
127 $log->addRelations( $field, $items, $row->log_id );
129 $prefix = substr( $field, 0, strpos( $field,
'_' ) );
130 if ( !isset( self::$tableMap[$prefix] ) ) {
133 $table = self::$tableMap[$prefix];
134 $userField = $prefix .
'_user';
135 $userTextField = $prefix .
'_user_text';
137 $userIds = $userIPs = [];
138 $sres = $db->select( $table,
139 [ $userField, $userTextField ],
140 [ $field => $items ],
143 foreach ( $sres as $srow ) {
144 if ( $srow->$userField > 0 ) {
145 $userIds[] = intval( $srow->$userField );
146 } elseif ( $srow->$userTextField !=
'' ) {
147 $userIPs[] = $srow->$userTextField;
151 $log->addRelations(
'target_author_id', $userIds, $row->log_id );
152 $log->addRelations(
'target_author_ip', $userIPs, $row->log_id );
153 } elseif ( LogEventsList::typeAction( $row, $delTypes,
'event' ) ) {
157 if ( count( $params ) < 1 ) {
160 $items = explode(
',', $params[0] );
161 $log =
new LogPage( $row->log_type );
163 $log->addRelations(
'log_id', $items, $row->log_id );
165 $userIds = $userIPs = [];
166 $sres = $db->select(
'logging',
167 [
'log_user',
'log_user_text' ],
168 [
'log_id' => $items ],
171 foreach ( $sres as $srow ) {
172 if ( $srow->log_user > 0 ) {
173 $userIds[] = intval( $srow->log_user );
174 } elseif (
Wikimedia\IPUtils::isIPAddress( $srow->log_user_text ) ) {
175 $userIPs[] = $srow->log_user_text;
178 $log->addRelations(
'target_author_id', $userIds, $row->log_id );
179 $log->addRelations(
'target_author_ip', $userIPs, $row->log_id );
182 $blockStart += $batchSize;
183 $blockEnd += $batchSize;
184 $lbFactory->waitForReplication();
186 $this->
output(
"Done populating log_search table.\n" );