31 parent::__construct();
32 $this->
addDescription(
'Remove autopatrol logs in the logging table' );
33 $this->
addOption(
'dry-run',
'Print debug info instead of actually deleting' );
36 'Check old patrol logs (for deleting old format autopatrols).'
40 'Timestamp to delete only before that time, all MediaWiki timestamp formats are accepted',
46 'First row (log id) to start updating from',
52 'Sleep time (in seconds) between every batch',
62 $sleep = (int)$this->
getOption(
'sleep', 10 );
63 $fromId = $this->
getOption(
'from-id',
null );
67 $rowsData = $this->getRowsOld( $fromId );
72 $rows = $rowsData[
'rows'];
73 $fromId = $rowsData[
'lastId'];
80 $rows = $this->getRows( $fromId );
84 $fromId = end( $rows );
88 $this->
output(
'These rows will get deleted: ' . implode(
', ', $rows ) .
"\n" );
90 $this->deleteRows( $rows );
91 $this->
output(
'Processed up to row id ' . end( $rows ) .
"\n" );
100 private function getRows( $fromId ) {
102 $before = $this->
getOption(
'before',
false );
105 'log_type' =>
'patrol',
106 'log_action' =>
'autopatrol',
110 $conds[] = $dbr->expr(
'log_id',
'>', $fromId );
114 $conds[] = $dbr->expr(
'log_timestamp',
'<', $dbr->timestamp( $before ) );
117 return $dbr->newSelectQueryBuilder()
121 ->orderBy(
'log_id' )
123 ->caller( __METHOD__ )
124 ->fetchFieldValues();
127 private function getRowsOld( $fromId ) {
130 $before = $this->
getOption(
'before',
false );
133 'log_type' =>
'patrol',
134 'log_action' =>
'patrol',
138 $conds[] = $dbr->expr(
'log_id',
'>', $fromId );
142 $conds[] = $dbr->expr(
'log_timestamp',
'<', $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();
168 if ( array_key_exists(
'6::auto',
$params ) ) {
170 $auto =
$params[
'6::auto'] ===
true;
171 } elseif ( $logEntry->isLegacy() ===
true && array_key_exists( 2,
$params ) ) {
179 $autopatrols[] = $row->log_id;
183 if ( $last ===
null ) {
187 return [
'rows' => $autopatrols,
'lastId' => $last ];
190 private function deleteRows( array $rows ) {
193 $dbw->newDeleteQueryBuilder()
194 ->deleteFrom(
'logging' )
195 ->where( [
'log_id' => $rows ] )
196 ->caller( __METHOD__ )->execute();
static newFromRow( $row)
Constructs new LogEntry from database result row.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
waitForReplication()
Wait for replica DBs to catch up.
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...
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.