19 require_once __DIR__ .
'/Maintenance.php';
29 parent::__construct();
30 $this->
addDescription(
'Remove autopatrol logs in the logging table' );
31 $this->
addOption(
'dry-run',
'Print debug info instead of actually deleting' );
34 'Check old patrol logs (for deleting old format autopatrols).'
38 'Timestamp to delete only before that time, all MediaWiki timestamp formats are accepted',
44 'First row (log id) to start updating from',
50 'Sleep time (in seconds) between every batch',
60 $sleep = (int)$this->
getOption(
'sleep', 10 );
61 $fromId = $this->
getOption(
'from-id',
null );
65 $rowsData = $this->getRowsOld( $fromId );
70 $rows = $rowsData[
'rows'];
71 $fromId = $rowsData[
'lastId'];
78 $rows = $this->getRows( $fromId );
82 $fromId = end( $rows );
86 $this->
output(
'These rows will get deleted: ' . implode(
', ', $rows ) .
"\n" );
88 $this->deleteRows( $rows );
89 $this->
output(
'Processed up to row id ' . end( $rows ) .
"\n" );
98 private function getRows( $fromId ) {
101 $before = $this->
getOption(
'before',
false );
104 'log_type' =>
'patrol',
105 'log_action' =>
'autopatrol',
109 $conds[] =
'log_id > ' .
$dbr->addQuotes( $fromId );
113 $conds[] =
'log_timestamp < ' .
$dbr->addQuotes(
$dbr->timestamp( $before ) );
116 return $dbr->newSelectQueryBuilder()
120 ->orderBy(
'log_id' )
122 ->caller( __METHOD__ )
123 ->fetchFieldValues();
126 private function getRowsOld( $fromId ) {
130 $before = $this->
getOption(
'before',
false );
133 'log_type' =>
'patrol',
134 'log_action' =>
'patrol',
138 $conds[] =
'log_id > ' .
$dbr->addQuotes( $fromId );
142 $conds[] =
'log_timestamp < ' .
$dbr->addQuotes(
$dbr->timestamp( $before ) );
145 $result =
$dbr->newSelectQueryBuilder()
146 ->select( [
'log_id',
'log_params' ] )
149 ->orderBy(
'log_id' )
150 ->limit( $batchSize )
151 ->caller( __METHOD__ )
156 foreach ( $result as $row ) {
157 $last = $row->log_id;
159 $params = $logEntry->getParameters();
160 if ( !is_array( $params ) ) {
168 if ( array_key_exists(
'6::auto', $params ) ) {
170 $auto = $params[
'6::auto'] ===
true;
171 } elseif ( $logEntry->isLegacy() ===
true && array_key_exists( 2, $params ) ) {
173 $auto = $params[2] ===
'1';
179 $autopatrols[] = $row->log_id;
183 if ( $last ===
null ) {
187 return [
'rows' => $autopatrols,
'lastId' => $last ];
190 private function deleteRows( array $rows ) {
196 [
'log_id' => $rows ],
201 $lbFactory->waitForReplication();
207 require_once RUN_MAINTENANCE_IF_MAIN;
static newFromRow( $row)
Constructs new LogEntry from database result row.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...
execute()
Do the actual work.
__construct()
Default constructor.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option was set.
countDown( $seconds)
Count down from $seconds to zero on the terminal, with a one-second pause between showing each number...
getBatchSize()
Returns batch size.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.