Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
93.94% |
31 / 33 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
PurgeOldLogIPData | |
100.00% |
31 / 31 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
execute | |
100.00% |
27 / 27 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\AbuseFilter\Maintenance; |
4 | |
5 | // @codeCoverageIgnoreStart |
6 | $IP = getenv( 'MW_INSTALL_PATH' ); |
7 | if ( $IP === false ) { |
8 | $IP = __DIR__ . '/../../..'; |
9 | } |
10 | require_once "$IP/maintenance/Maintenance.php"; |
11 | // @codeCoverageIgnoreEnd |
12 | |
13 | use Maintenance; |
14 | use MediaWiki\Utils\MWTimestamp; |
15 | |
16 | class PurgeOldLogIPData extends Maintenance { |
17 | public function __construct() { |
18 | parent::__construct(); |
19 | $this->addDescription( 'Purge old IP address data from the abuse_filter_log table' ); |
20 | $this->setBatchSize( 200 ); |
21 | |
22 | $this->requireExtension( 'Abuse Filter' ); |
23 | } |
24 | |
25 | /** |
26 | * @inheritDoc |
27 | */ |
28 | public function execute() { |
29 | $this->output( "Purging old data from abuse_filter_log...\n" ); |
30 | $dbw = $this->getDB( DB_PRIMARY ); |
31 | $cutoffUnix = (int)MWTimestamp::now( TS_UNIX ) - $this->getConfig()->get( 'AbuseFilterLogIPMaxAge' ); |
32 | |
33 | $count = 0; |
34 | do { |
35 | $ids = $dbw->selectFieldValues( |
36 | 'abuse_filter_log', |
37 | 'afl_id', |
38 | [ |
39 | 'afl_ip <> ' . $dbw->addQuotes( '' ), |
40 | "afl_timestamp < " . $dbw->addQuotes( $dbw->timestamp( $cutoffUnix ) ) |
41 | ], |
42 | __METHOD__, |
43 | [ 'LIMIT' => $this->getBatchSize() ] |
44 | ); |
45 | |
46 | if ( $ids ) { |
47 | $dbw->newUpdateQueryBuilder() |
48 | ->update( 'abuse_filter_log' ) |
49 | ->set( [ 'afl_ip' => '' ] ) |
50 | ->where( [ 'afl_id' => $ids ] ) |
51 | ->caller( __METHOD__ ) |
52 | ->execute(); |
53 | $count += $dbw->affectedRows(); |
54 | $this->output( "$count\n" ); |
55 | |
56 | $this->waitForReplication(); |
57 | } |
58 | } while ( count( $ids ) >= $this->getBatchSize() ); |
59 | |
60 | $this->output( "$count rows.\n" ); |
61 | |
62 | $this->output( "Done.\n" ); |
63 | } |
64 | |
65 | } |
66 | |
67 | $maintClass = PurgeOldLogIPData::class; |
68 | require_once RUN_MAINTENANCE_IF_MAIN; |