Write maintenance script for AbuseFilter to purge old IP data from logs

Bug: 51573
Change-Id: I93392d77fb6172d55353d2ba7fb1be3a19f13b11
This commit is contained in:
Reedy 2013-08-27 18:00:27 +01:00
parent bed98b4bb2
commit cac808a35c
2 changed files with 55 additions and 0 deletions

View file

@ -209,3 +209,5 @@ $wgAbuseFilterValidGroups = array('default');
$wgAbuseFilterDefaultWarningMessage = array(
'default' => 'abusefilter-warning',
);
$wgAbuseFilterLogIPMaxAge = 3 * 30 * 24 * 3600; // 3 months

View 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 );