mediawiki-extensions-AbuseF.../maintenance/purgeOldLogIPData.php
Daimona Eaytoy b4346678c6 Replace deprecated wfWaitForSlaves
Deprecated since 1.27.

Change-Id: I16787520dd4939e6d1579261ac35a4a1f6288b70
2019-03-29 11:01:37 +01:00

66 lines
1.5 KiB
PHP

<?php
if ( getenv( 'MW_INSTALL_PATH' ) ) {
$IP = getenv( 'MW_INSTALL_PATH' );
} else {
$IP = __DIR__ . '/../../..';
}
require_once "$IP/maintenance/Maintenance.php";
use MediaWiki\MediaWikiServices;
class PurgeOldLogIPData extends Maintenance {
public function __construct() {
parent::__construct();
$this->addDescription( 'Purge old IP Address data from AbuseFilter logs' );
$this->setBatchSize( 200 );
$this->requireExtension( 'Abuse Filter' );
}
/**
* @see Maintenance:execute()
*/
public function execute() {
$this->output( "Purging old IP Address data from abuse_filter_log...\n" );
$dbw = wfGetDB( DB_MASTER );
$factory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
$cutoffUnix = time() - $this->getConfig()->get( 'AbuseFilterLogIPMaxAge' );
$count = 0;
do {
$ids = $dbw->selectFieldValues(
'abuse_filter_log',
'afl_id',
[
'afl_ip <> ""',
"afl_timestamp < " . $dbw->addQuotes( $dbw->timestamp( $cutoffUnix ) )
],
__METHOD__,
[ 'LIMIT' => $this->getBatchSize() ]
);
if ( $ids ) {
$dbw->update(
'abuse_filter_log',
[ 'afl_ip' => '' ],
[ 'afl_id' => $ids ],
__METHOD__
);
$count += $dbw->affectedRows();
$this->output( "$count\n" );
$factory->waitForReplication();
}
} while ( count( $ids ) >= $this->getBatchSize() );
$this->output( "$count rows.\n" );
$this->output( "Done.\n" );
}
}
$maintClass = PurgeOldLogIPData::class;
require_once RUN_MAINTENANCE_IF_MAIN;