Reedy has uploaded a new change for review. https://gerrit.wikimedia.org/r/81255
Change subject: Write maintenance script for AbuseFilter to purge old IP data from logs ...................................................................... Write maintenance script for AbuseFilter to purge old IP data from logs Bug: 51573 Change-Id: I93392d77fb6172d55353d2ba7fb1be3a19f13b11 --- M AbuseFilter.php A maintenance/purgeOldLogIPData.php 2 files changed, 54 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/AbuseFilter refs/changes/55/81255/1 diff --git a/AbuseFilter.php b/AbuseFilter.php index 1b0a55a..d517e26 100644 --- a/AbuseFilter.php +++ b/AbuseFilter.php @@ -209,3 +209,5 @@ $wgAbuseFilterDefaultWarningMessage = array( 'default' => 'abusefilter-warning', ); + +$wgAbuseFilterLogIPMaxAge = 3 * 30 * 24 * 3600; // 3 months diff --git a/maintenance/purgeOldLogIPData.php b/maintenance/purgeOldLogIPData.php new file mode 100644 index 0000000..e903f0e --- /dev/null +++ b/maintenance/purgeOldLogIPData.php @@ -0,0 +1,52 @@ +<?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; + + $this->output( "Purging old IP Address data from abuse_filter_log..." ); + $dbw = wfGetDB( DB_MASTER ); + + $count = 0; + while ( true ) { + $dbw->begin(); + $res = $dbw->update( + 'abuse_filter_log', + array( 'afl_ip' => '' ), + array( + 'afl_ip <> ""', + "afl_timestamp < " . $dbw->addQuotes( $dbw->timestamp( time() - $wgAbuseFilterLogIPMaxAge ) ) + ), + __METHOD__ + ); + $count += $dbw->affectedRows(); + $dbw->commit(); + if ( !$res->numRows() ) { + break; // all cleared + } + + wfWaitForSlaves(); + } + + $this->output( $count . " rows.\n" ); + + $this->output( "Done.\n" ); + } + +} + +$maintClass = "PurgeOldLogIPData"; +require_once( RUN_MAINTENANCE_IF_MAIN ); -- To view, visit https://gerrit.wikimedia.org/r/81255 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I93392d77fb6172d55353d2ba7fb1be3a19f13b11 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/AbuseFilter Gerrit-Branch: master Gerrit-Owner: Reedy <re...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits