22require_once __DIR__ .
'/Maintenance.php';
33 parent::__construct();
34 $this->
addDescription(
'Remove autopatrol logs in the logging table' );
35 $this->
addOption(
'dry-run',
'Print debug info instead of actually deleting' );
38 'Check old patrol logs (for deleting old format autopatrols).'
42 'Timestamp to delete only before that time, all MediaWiki timestamp formats are accepted',
48 'First row (log id) to start updating from',
54 'Sleep time (in seconds) between every batch',
64 $sleep = (int)$this->
getOption(
'sleep', 10 );
65 $fromId = $this->
getOption(
'from-id',
null );
69 $rowsData = $this->getRowsOld( $fromId );
74 $rows = $rowsData[
'rows'];
75 $fromId = $rowsData[
'lastId'];
82 $rows = $this->getRows( $fromId );
86 $fromId = end( $rows );
90 $this->
output(
'These rows will get deleted: ' . implode(
', ', $rows ) .
"\n" );
92 $this->deleteRows( $rows );
93 $this->
output(
'Processed up to row id ' . end( $rows ) .
"\n" );
102 private function getRows( $fromId ) {
104 $before = $this->
getOption(
'before',
false );
107 'log_type' =>
'patrol',
108 'log_action' =>
'autopatrol',
112 $conds[] = $dbr->expr(
'log_id',
'>', $fromId );
116 $conds[] = $dbr->expr(
'log_timestamp',
'<', $dbr->timestamp( $before ) );
119 return $dbr->newSelectQueryBuilder()
123 ->orderBy(
'log_id' )
125 ->caller( __METHOD__ )
126 ->fetchFieldValues();
129 private function getRowsOld( $fromId ) {
132 $before = $this->
getOption(
'before',
false );
135 'log_type' =>
'patrol',
136 'log_action' =>
'patrol',
140 $conds[] = $dbr->expr(
'log_id',
'>', $fromId );
144 $conds[] = $dbr->expr(
'log_timestamp',
'<', $dbr->timestamp( $before ) );
147 $result = $dbr->newSelectQueryBuilder()
148 ->select( [
'log_id',
'log_params' ] )
151 ->orderBy(
'log_id' )
152 ->limit( $batchSize )
153 ->caller( __METHOD__ )
158 foreach ( $result as $row ) {
159 $last = $row->log_id;
161 $params = $logEntry->getParameters();
170 if ( array_key_exists(
'6::auto',
$params ) ) {
172 $auto =
$params[
'6::auto'] ===
true;
173 } elseif ( $logEntry->isLegacy() ===
true && array_key_exists( 2,
$params ) ) {
181 $autopatrols[] = $row->log_id;
185 if ( $last ===
null ) {
189 return [
'rows' => $autopatrols,
'lastId' => $last ];
192 private function deleteRows( array $rows ) {
195 $dbw->newDeleteQueryBuilder()
196 ->deleteFrom(
'logging' )
197 ->where( [
'log_id' => $rows ] )
198 ->caller( __METHOD__ )->execute();
207require_once RUN_MAINTENANCE_IF_MAIN;
array $params
The job parameters.
static newFromRow( $row)
Constructs new LogEntry from database result row.
Remove autopatrol logs in the logging table.
execute()
Do the actual work.
__construct()
Default constructor.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
getBatchSize()
Returns batch size.
output( $out, $channel=null)
Throw some output to the user.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
waitForReplication()
Wait for replica DB servers to catch up.
hasOption( $name)
Checks to see if a particular option was set.
getOption( $name, $default=null)
Get an option, or return the default.
countDown( $seconds)
Count down from $seconds to zero on the terminal, with a one-second pause between showing each number...
addDescription( $text)
Set the description text.