2013-08-27 17:00:27 +00:00
|
|
|
<?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;
|
|
|
|
|
2014-01-03 17:54:59 +00:00
|
|
|
$this->output( "Purging old IP Address data from abuse_filter_log...\n" );
|
2013-08-27 17:00:27 +00:00
|
|
|
$dbw = wfGetDB( DB_MASTER );
|
2015-04-08 02:28:01 +00:00
|
|
|
$cutoffUnix = time() - $wgAbuseFilterLogIPMaxAge;
|
2013-08-27 17:00:27 +00:00
|
|
|
|
|
|
|
$count = 0;
|
2015-04-08 02:28:01 +00:00
|
|
|
do {
|
|
|
|
$ids = $dbw->selectFieldValues(
|
2013-08-27 17:00:27 +00:00
|
|
|
'abuse_filter_log',
|
2015-04-08 02:28:01 +00:00
|
|
|
'afl_id',
|
2013-08-27 17:00:27 +00:00
|
|
|
array(
|
|
|
|
'afl_ip <> ""',
|
2015-04-08 02:28:01 +00:00
|
|
|
"afl_timestamp < " . $dbw->addQuotes( $dbw->timestamp( $cutoffUnix ) )
|
2013-08-27 17:00:27 +00:00
|
|
|
),
|
|
|
|
__METHOD__,
|
|
|
|
array( 'LIMIT' => $this->mBatchSize )
|
|
|
|
);
|
|
|
|
|
2015-04-08 02:28:01 +00:00
|
|
|
if ( $ids ) {
|
|
|
|
$dbw->update(
|
|
|
|
'abuse_filter_log',
|
|
|
|
array( 'afl_ip' => '' ),
|
|
|
|
array( 'afl_id' => $ids ),
|
|
|
|
__METHOD__
|
|
|
|
);
|
|
|
|
$count += $dbw->affectedRows();
|
|
|
|
$this->output( "$count\n" );
|
|
|
|
|
|
|
|
wfWaitForSlaves();
|
|
|
|
}
|
|
|
|
} while ( count( $ids ) >= $this->mBatchSize );
|
2013-08-27 17:00:27 +00:00
|
|
|
|
2014-01-03 17:54:59 +00:00
|
|
|
$this->output( "$count rows.\n" );
|
2013-08-27 17:00:27 +00:00
|
|
|
|
|
|
|
$this->output( "Done.\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$maintClass = "PurgeOldLogIPData";
|
|
|
|
require_once( RUN_MAINTENANCE_IF_MAIN );
|