25 require_once __DIR__ .
'/Maintenance.php';
34 static $tableMap =
array(
'rev' =>
'revision',
'fa' =>
'filearchive',
'oi' =>
'oldimage',
'ar' =>
'archive' );
37 parent::__construct();
38 $this->mDescription =
"Migrate log params to new table and index for searching";
43 return 'populate log_search';
47 return 'log_search table already populated.';
52 if ( !$db->tableExists(
'log_search' ) ) {
53 $this->
error(
"log_search does not exist" );
56 $start = $db->selectField(
'logging',
'MIN(log_id)',
false, __FUNCTION__ );
58 $this->
output(
"Nothing to do.\n" );
61 $end = $db->selectField(
'logging',
'MAX(log_id)',
false, __FUNCTION__ );
64 $end += $this->mBatchSize - 1;
66 $blockEnd = $start + $this->mBatchSize - 1;
68 $delTypes =
array(
'delete',
'suppress' );
69 while ( $blockEnd <= $end ) {
70 $this->
output(
"...doing log_id from $blockStart to $blockEnd\n" );
71 $cond =
"log_id BETWEEN $blockStart AND $blockEnd";
72 $res = $db->select(
'logging',
'*', $cond, __FUNCTION__ );
83 if ( $field ==
null ) {
86 if ( $field ==
null ) {
87 $this->
output(
"Invalid param type for {$row->log_id}\n" );
91 $db->update(
'logging',
93 array(
'log_id' => $row->log_id ) );
96 $items = explode(
',',
$params[1] );
97 $log =
new LogPage( $row->log_type );
99 $log->addRelations( $field, $items, $row->log_id );
101 $prefix = substr( $field, 0, strpos( $field,
'_' ) );
102 if ( !isset( self::$tableMap[$prefix] ) ) {
105 $table = self::$tableMap[$prefix];
106 $userField = $prefix .
'_user';
107 $userTextField = $prefix .
'_user_text';
109 $userIds = $userIPs =
array();
110 $sres = $db->select( $table,
111 array( $userField, $userTextField ),
112 array( $field => $items )
114 foreach ( $sres
as $srow ) {
115 if ( $srow->$userField > 0 ) {
116 $userIds[] = intval( $srow->$userField );
117 } elseif ( $srow->$userTextField !=
'' ) {
118 $userIPs[] = $srow->$userTextField;
122 $log->addRelations(
'target_author_id', $userIds, $row->log_id );
123 $log->addRelations(
'target_author_ip', $userIPs, $row->log_id );
131 $items = explode(
',',
$params[0] );
132 $log =
new LogPage( $row->log_type );
134 $log->addRelations(
'log_id', $items, $row->log_id );
136 $userIds = $userIPs =
array();
137 $sres = $db->select(
'logging',
138 array(
'log_user',
'log_user_text' ),
139 array(
'log_id' => $items )
141 foreach ( $sres
as $srow ) {
142 if ( $srow->log_user > 0 ) {
143 $userIds[] = intval( $srow->log_user );
145 $userIPs[] = $srow->log_user_text;
148 $log->addRelations(
'target_author_id', $userIds, $row->log_id );
149 $log->addRelations(
'target_author_ip', $userIPs, $row->log_id );
156 $this->
output(
"Done populating log_search table.\n" );