mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-23 21:53:35 +00:00
Write maintenance script for AbuseFilter to purge old IP data from logs
Bug: 51573 Change-Id: I93392d77fb6172d55353d2ba7fb1be3a19f13b11
This commit is contained in:
parent
bed98b4bb2
commit
cac808a35c
|
@ -209,3 +209,5 @@ $wgAbuseFilterValidGroups = array('default');
|
|||
$wgAbuseFilterDefaultWarningMessage = array(
|
||||
'default' => 'abusefilter-warning',
|
||||
);
|
||||
|
||||
$wgAbuseFilterLogIPMaxAge = 3 * 30 * 24 * 3600; // 3 months
|
||||
|
|
53
maintenance/purgeOldLogIPData.php
Normal file
53
maintenance/purgeOldLogIPData.php
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
if ( getenv( 'MW_INSTALL_PATH' ) ) {
|
||||
$IP = getenv( 'MW_INSTALL_PATH' );
|
||||
} else {
|
||||
$IP = dirname( __FILE__ ) . '/../../..';
|
||||
}
|
||||
require_once( "$IP/maintenance/Maintenance.php" );
|
||||
|
||||
class PurgeOldLogIPData extends Maintenance {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->mDescription = "Purge old IP Address data from AbuseFilter logs";
|
||||
$this->setBatchSize( 200 );
|
||||
}
|
||||
|
||||
public function execute() {
|
||||
global $wgAbuseFilterLogIPMaxAge;
|
||||
|
||||
$this->output( "Purging old IP Address data from abuse_filter_log..." );
|
||||
$dbw = wfGetDB( DB_MASTER );
|
||||
|
||||
$count = 0;
|
||||
while ( true ) {
|
||||
$dbw->begin();
|
||||
$res = $dbw->update(
|
||||
'abuse_filter_log',
|
||||
array( 'afl_ip' => '' ),
|
||||
array(
|
||||
'afl_ip <> ""',
|
||||
"afl_timestamp < " . $dbw->addQuotes( $dbw->timestamp( time() - $wgAbuseFilterLogIPMaxAge ) )
|
||||
),
|
||||
__METHOD__,
|
||||
array( 'LIMIT' => $this->mBatchSize )
|
||||
);
|
||||
$count += $dbw->affectedRows();
|
||||
$dbw->commit();
|
||||
if ( $res->numRows() < $this->mBatchSize ) {
|
||||
break; // all updated
|
||||
}
|
||||
|
||||
wfWaitForSlaves();
|
||||
}
|
||||
|
||||
$this->output( $count . " rows.\n" );
|
||||
|
||||
$this->output( "Done.\n" );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$maintClass = "PurgeOldLogIPData";
|
||||
require_once( RUN_MAINTENANCE_IF_MAIN );
|
Loading…
Reference in a new issue