25 require_once __DIR__ .
'/Maintenance.php';
36 'fa' =>
'filearchive',
42 parent::__construct();
43 $this->
addDescription(
'Migrate log params to new table and index for searching' );
48 return 'populate log_search';
52 return 'log_search table already populated.';
58 if ( !$db->tableExists(
'log_search' ) ) {
59 $this->
error(
"log_search does not exist" );
63 $start = $db->selectField(
'logging',
'MIN(log_id)',
'', __FUNCTION__ );
65 $this->
output(
"Nothing to do.\n" );
69 $end = $db->selectField(
'logging',
'MAX(log_id)',
'', __FUNCTION__ );
74 if ( !$db->fieldExists(
'logging',
'log_user' ) ) {
76 "This does not appear to be an upgrade from MediaWiki pre-1.16 "
77 .
"(logging.log_user does not exist).\n"
79 $this->
output(
"Nothing to do.\n" );
85 $end += $batchSize - 1;
87 $blockEnd = $start + $batchSize - 1;
89 $delTypes = [
'delete',
'suppress' ];
90 while ( $blockEnd <= $end ) {
91 $this->
output(
"...doing log_id from $blockStart to $blockEnd\n" );
92 $cond =
"log_id BETWEEN " . (int)$blockStart .
" AND " . (
int)$blockEnd;
94 'logging', [
'log_id',
'log_type',
'log_action',
'log_params' ], $cond, __FUNCTION__
96 foreach (
$res as $row ) {
101 if ( count( $params ) < 2 ) {
106 if ( $field ==
null ) {
107 array_shift( $params );
109 if ( $field ==
null ) {
110 $this->
output(
"Invalid param type for {$row->log_id}\n" );
114 $db->update(
'logging',
115 [
'log_params' => implode(
',', $params ) ],
116 [
'log_id' => $row->log_id ] );
119 $items = explode(
',', $params[1] );
120 $log =
new LogPage( $row->log_type );
122 $log->addRelations( $field, $items, $row->log_id );
124 $prefix = substr( $field, 0, strpos( $field,
'_' ) );
125 if ( !isset( self::$tableMap[$prefix] ) ) {
128 $table = self::$tableMap[$prefix];
129 $userField = $prefix .
'_user';
130 $userTextField = $prefix .
'_user_text';
132 $userIds = $userIPs = [];
133 $sres = $db->select( $table,
134 [ $userField, $userTextField ],
137 foreach ( $sres as $srow ) {
138 if ( $srow->$userField > 0 ) {
139 $userIds[] = intval( $srow->$userField );
140 } elseif ( $srow->$userTextField !=
'' ) {
141 $userIPs[] = $srow->$userTextField;
145 $log->addRelations(
'target_author_id', $userIds, $row->log_id );
146 $log->addRelations(
'target_author_ip', $userIPs, $row->log_id );
151 if ( count( $params ) < 1 ) {
154 $items = explode(
',', $params[0] );
155 $log =
new LogPage( $row->log_type );
157 $log->addRelations(
'log_id', $items, $row->log_id );
159 $userIds = $userIPs = [];
160 $sres = $db->select(
'logging',
161 [
'log_user',
'log_user_text' ],
162 [
'log_id' => $items ]
164 foreach ( $sres as $srow ) {
165 if ( $srow->log_user > 0 ) {
166 $userIds[] = intval( $srow->log_user );
168 $userIPs[] = $srow->log_user_text;
171 $log->addRelations(
'target_author_id', $userIds, $row->log_id );
172 $log->addRelations(
'target_author_ip', $userIPs, $row->log_id );
175 $blockStart += $batchSize;
176 $blockEnd += $batchSize;
179 $this->
output(
"Done populating log_search table.\n" );