2013-08-27 17:00:27 +00:00
|
|
|
<?php
|
|
|
|
|
2021-01-02 13:49:41 +00:00
|
|
|
namespace MediaWiki\Extension\AbuseFilter\Maintenance;
|
|
|
|
|
2021-01-17 11:54:43 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2022-09-22 22:20:32 +00:00
|
|
|
$IP = getenv( 'MW_INSTALL_PATH' );
|
|
|
|
if ( $IP === false ) {
|
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";
|
2021-01-17 11:54:43 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|
2013-08-27 17:00:27 +00:00
|
|
|
|
2021-01-02 13:49:41 +00:00
|
|
|
use Maintenance;
|
2023-12-10 19:03:19 +00:00
|
|
|
use MediaWiki\Utils\MWTimestamp;
|
2019-03-29 10:00:18 +00:00
|
|
|
|
2013-08-27 17:00:27 +00:00
|
|
|
class PurgeOldLogIPData extends Maintenance {
|
|
|
|
public function __construct() {
|
|
|
|
parent::__construct();
|
2022-09-22 22:20:32 +00:00
|
|
|
$this->addDescription( 'Purge old IP address data from the abuse_filter_log table' );
|
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
|
|
|
/**
|
2020-12-03 08:49:56 +00:00
|
|
|
* @inheritDoc
|
2018-04-04 21:14:25 +00:00
|
|
|
*/
|
2013-08-27 17:00:27 +00:00
|
|
|
public function execute() {
|
2022-09-22 22:20:32 +00:00
|
|
|
$this->output( "Purging old data from abuse_filter_log...\n" );
|
2023-03-03 17:32:00 +00:00
|
|
|
$dbw = $this->getDB( DB_PRIMARY );
|
2021-01-17 11:54:43 +00:00
|
|
|
$cutoffUnix = (int)MWTimestamp::now( TS_UNIX ) - $this->getConfig()->get( 'AbuseFilterLogIPMaxAge' );
|
2013-08-27 17:00:27 +00:00
|
|
|
|
|
|
|
$count = 0;
|
2015-04-08 02:28:01 +00:00
|
|
|
do {
|
2024-04-29 20:15:35 +00:00
|
|
|
$ids = $dbw->newSelectQueryBuilder()
|
|
|
|
->select( 'afl_id' )
|
|
|
|
->from( 'abuse_filter_log' )
|
|
|
|
->where( [
|
|
|
|
$dbw->expr( 'afl_ip', '!=', '' ),
|
|
|
|
$dbw->expr( 'afl_timestamp', '<', $dbw->timestamp( $cutoffUnix ) ),
|
|
|
|
] )
|
|
|
|
->limit( $this->getBatchSize() )
|
|
|
|
->caller( __METHOD__ )
|
|
|
|
->fetchFieldValues();
|
2013-08-27 17:00:27 +00:00
|
|
|
|
2015-04-08 02:28:01 +00:00
|
|
|
if ( $ids ) {
|
2024-04-15 19:49:52 +00:00
|
|
|
$dbw->newUpdateQueryBuilder()
|
|
|
|
->update( 'abuse_filter_log' )
|
|
|
|
->set( [ 'afl_ip' => '' ] )
|
|
|
|
->where( [ 'afl_id' => $ids ] )
|
|
|
|
->caller( __METHOD__ )
|
|
|
|
->execute();
|
2015-04-08 02:28:01 +00:00
|
|
|
$count += $dbw->affectedRows();
|
|
|
|
$this->output( "$count\n" );
|
|
|
|
|
2023-03-03 17:32:00 +00:00
|
|
|
$this->waitForReplication();
|
2015-04-08 02:28:01 +00:00
|
|
|
}
|
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" );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-03-03 00:41:40 +00:00
|
|
|
$maintClass = PurgeOldLogIPData::class;
|
2015-09-28 18:03:35 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|