2013-08-27 17:00:27 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
if ( getenv( 'MW_INSTALL_PATH' ) ) {
|
|
|
|
$IP = getenv( 'MW_INSTALL_PATH' );
|
|
|
|
} else {
|
2015-09-28 18:03:35 +00:00
|
|
|
$IP = __DIR__ . '/../../..';
|
2013-08-27 17:00:27 +00:00
|
|
|
}
|
2015-09-28 18:03:35 +00:00
|
|
|
require_once "$IP/maintenance/Maintenance.php";
|
2013-08-27 17:00:27 +00:00
|
|
|
|
|
|
|
class PurgeOldLogIPData extends Maintenance {
|
|
|
|
public function __construct() {
|
|
|
|
parent::__construct();
|
2015-09-28 18:03:35 +00:00
|
|
|
$this->mDescription = 'Purge old IP Address data from AbuseFilter logs';
|
2013-08-27 17:00:27 +00:00
|
|
|
$this->setBatchSize( 200 );
|
2016-12-12 21:29:51 +00:00
|
|
|
|
2018-02-10 00:45:16 +00:00
|
|
|
$this->requireExtension( 'Abuse Filter' );
|
2013-08-27 17:00:27 +00:00
|
|
|
}
|
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* @see Maintenance:execute()
|
|
|
|
*/
|
2013-08-27 17:00:27 +00:00
|
|
|
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',
|
2017-06-15 14:23:34 +00:00
|
|
|
[
|
2013-08-27 17:00:27 +00:00
|
|
|
'afl_ip <> ""',
|
2015-04-08 02:28:01 +00:00
|
|
|
"afl_timestamp < " . $dbw->addQuotes( $dbw->timestamp( $cutoffUnix ) )
|
2017-06-15 14:23:34 +00:00
|
|
|
],
|
2013-08-27 17:00:27 +00:00
|
|
|
__METHOD__,
|
2017-11-08 03:39:34 +00:00
|
|
|
[ 'LIMIT' => $this->getBatchSize() ]
|
2013-08-27 17:00:27 +00:00
|
|
|
);
|
|
|
|
|
2015-04-08 02:28:01 +00:00
|
|
|
if ( $ids ) {
|
|
|
|
$dbw->update(
|
|
|
|
'abuse_filter_log',
|
2017-06-15 14:23:34 +00:00
|
|
|
[ 'afl_ip' => '' ],
|
|
|
|
[ 'afl_id' => $ids ],
|
2015-04-08 02:28:01 +00:00
|
|
|
__METHOD__
|
|
|
|
);
|
|
|
|
$count += $dbw->affectedRows();
|
|
|
|
$this->output( "$count\n" );
|
|
|
|
|
|
|
|
wfWaitForSlaves();
|
|
|
|
}
|
2017-11-08 03:39:34 +00:00
|
|
|
} while ( count( $ids ) >= $this->getBatchSize() );
|
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";
|
2015-09-28 18:03:35 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|