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;
|
2019-03-29 10:00:18 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2021-01-17 11:54:43 +00:00
|
|
|
use 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" );
|
2021-05-02 06:41:53 +00:00
|
|
|
$dbw = wfGetDB( DB_PRIMARY );
|
2019-03-29 10:00:18 +00:00
|
|
|
$factory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
|
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 {
|
|
|
|
$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
|
|
|
[
|
2022-07-09 21:40:15 +00:00
|
|
|
'afl_ip <> ' . $dbw->addQuotes( '' ),
|
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" );
|
|
|
|
|
2019-03-29 10:00:18 +00:00
|
|
|
$factory->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;
|