mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-23 21:53:35 +00:00
Remove leftovers of AbuseFilterAflFilterMigrationStage
On second thought, no need to keep the migration script now, since it's unusable anyway. Also remove an usage in SpecialAbuseLog, likely a rebase artefact. Change-Id: I938924b3617ef30046d8317e68a101ed2c1883d3
This commit is contained in:
parent
a332b3ff0f
commit
020f8a09b4
|
@ -4,7 +4,6 @@ namespace MediaWiki\Extension\AbuseFilter\Hooks\Handlers;
|
|||
|
||||
use DatabaseUpdater;
|
||||
use MediaWiki\Extension\AbuseFilter\Maintenance\FixOldLogEntries;
|
||||
use MediaWiki\Extension\AbuseFilter\Maintenance\MigrateAflFilter;
|
||||
use MediaWiki\Extension\AbuseFilter\Maintenance\NormalizeThrottleParameters;
|
||||
use MediaWiki\Extension\AbuseFilter\Maintenance\UpdateVarDumps;
|
||||
use MediaWiki\Installer\Hook\LoadExtensionSchemaUpdatesHook;
|
||||
|
@ -49,8 +48,6 @@ class SchemaChangesHandler implements LoadExtensionSchemaUpdatesHook {
|
|||
* @throws MWException
|
||||
*/
|
||||
public function onLoadExtensionSchemaUpdates( $updater ) {
|
||||
global $wgAbuseFilterAflFilterMigrationStage;
|
||||
|
||||
$dbType = $updater->getDB()->getType();
|
||||
$dir = __DIR__ . "/../../../db_patches";
|
||||
|
||||
|
@ -120,13 +117,6 @@ class SchemaChangesHandler implements LoadExtensionSchemaUpdatesHook {
|
|||
$updater->addPostDatabaseUpdateMaintenance( NormalizeThrottleParameters::class );
|
||||
$updater->addPostDatabaseUpdateMaintenance( FixOldLogEntries::class );
|
||||
$updater->addPostDatabaseUpdateMaintenance( UpdateVarDumps::class );
|
||||
// The global is not set on install.php
|
||||
if (
|
||||
isset( $wgAbuseFilterAflFilterMigrationStage ) &&
|
||||
( $wgAbuseFilterAflFilterMigrationStage & SCHEMA_COMPAT_WRITE_NEW )
|
||||
) {
|
||||
$updater->addPostDatabaseUpdateMaintenance( MigrateAflFilter::class );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -650,7 +650,6 @@ class SpecialAbuseLog extends AbuseFilterSpecialPage {
|
|||
public function showDetails( $id ) {
|
||||
$out = $this->getOutput();
|
||||
$user = $this->getUser();
|
||||
$aflFilterMigrationStage = $this->getConfig()->get( 'AbuseFilterAflFilterMigrationStage' );
|
||||
|
||||
$pager = new AbuseLogPager(
|
||||
$this->getContext(),
|
||||
|
|
|
@ -1,143 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\AbuseFilter\Maintenance;
|
||||
|
||||
use LoggedUpdateMaintenance;
|
||||
use MediaWiki\Extension\AbuseFilter\GlobalNameUtils;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
if ( getenv( 'MW_INSTALL_PATH' ) ) {
|
||||
$IP = getenv( 'MW_INSTALL_PATH' );
|
||||
} else {
|
||||
$IP = __DIR__ . '/../../..';
|
||||
}
|
||||
require_once "$IP/maintenance/Maintenance.php";
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
/**
|
||||
* Split afl_filter in afl_filter_id and afl_global per T42757
|
||||
* @codeCoverageIgnore Single-use script
|
||||
*/
|
||||
class MigrateAflFilter extends LoggedUpdateMaintenance {
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
$this->addOption( 'dry-run', 'Perform a dry run' );
|
||||
$this->requireExtension( 'Abuse Filter' );
|
||||
$this->setBatchSize( 500 );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getUpdateKey() {
|
||||
return 'MigrateAflFilter';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function doDBUpdates() {
|
||||
$aflFilterMigrationStage = $this->getConfig()->get( 'AbuseFilterAflFilterMigrationStage' );
|
||||
|
||||
// Keep this check in place in case the script is executed manually
|
||||
if ( !( $aflFilterMigrationStage & SCHEMA_COMPAT_WRITE_NEW ) ) {
|
||||
$this->output(
|
||||
"...cannot update while \$wgAbuseFilterAflFilterMigrationStage lacks SCHEMA_COMPAT_WRITE_NEW\n"
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
$dryRun = $this->hasOption( 'dry-run' );
|
||||
$lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
|
||||
$dbw = $lbFactory->getMainLB()->getConnection( DB_PRIMARY );
|
||||
$globalPrefix = GlobalNameUtils::GLOBAL_FILTER_PREFIX;
|
||||
|
||||
$batchSize = $this->getBatchSize();
|
||||
$updated = 0;
|
||||
|
||||
$prevID = 1;
|
||||
$curID = $batchSize;
|
||||
|
||||
// Save the row count, and stop once it's reached. This is so that we can tolerate rows with
|
||||
// low IDs that were already updated in a previous execution.
|
||||
$allRowsCount = (int)$dbw->selectField(
|
||||
'abuse_filter_log',
|
||||
'MAX(afl_id)',
|
||||
[],
|
||||
__METHOD__
|
||||
);
|
||||
|
||||
do {
|
||||
$this->output( "... processing afl_id's from $prevID to $curID\n" );
|
||||
$updateIDs = $dbw->selectFieldValues(
|
||||
'abuse_filter_log',
|
||||
'afl_id',
|
||||
[
|
||||
// Use the primary key to avoid slow queries (and enforce batch size)
|
||||
"afl_id >= $prevID",
|
||||
"afl_id <= $curID",
|
||||
// Skip updated rows straight away
|
||||
'afl_filter_id' => 0
|
||||
],
|
||||
__METHOD__
|
||||
);
|
||||
|
||||
$count = count( $updateIDs );
|
||||
|
||||
$prevID = $curID + 1;
|
||||
$curID += $batchSize;
|
||||
$updated += $count;
|
||||
|
||||
if ( $count === 0 ) {
|
||||
// Can mostly happen if we're on low IDs but they were already updated
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( !$dryRun ) {
|
||||
// Use native SQL functions instead of GlobalNameUtils::splitGlobalName so that we can update
|
||||
// all rows at the same time.
|
||||
$newIdSQL = $dbw->buildIntegerCast( $dbw->strreplace(
|
||||
'afl_filter',
|
||||
$dbw->addQuotes( $globalPrefix ),
|
||||
$dbw->addQuotes( '' )
|
||||
) );
|
||||
$globalSQL = $dbw->buildIntegerCast(
|
||||
'(' . $dbw->buildSubstring( 'afl_filter', 1, strlen( $globalPrefix ) ) . ' = ' .
|
||||
$dbw->addQuotes( $globalPrefix ) . ' )'
|
||||
);
|
||||
|
||||
$dbw->update(
|
||||
'abuse_filter_log',
|
||||
[
|
||||
"afl_filter_id = $newIdSQL",
|
||||
"afl_global = $globalSQL"
|
||||
],
|
||||
[ 'afl_id' => $updateIDs ],
|
||||
__METHOD__
|
||||
);
|
||||
$lbFactory->waitForReplication();
|
||||
}
|
||||
} while ( $prevID <= $allRowsCount );
|
||||
|
||||
if ( $updated === 0 ) {
|
||||
$this->output( "No rows to change\n" );
|
||||
return !$dryRun;
|
||||
}
|
||||
|
||||
if ( $dryRun ) {
|
||||
$this->output( "Found $updated rows to migrate in abuse_filter_log\n" );
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->output( "Migrated $updated rows.\n" );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$maintClass = MigrateAflFilter::class;
|
||||
require_once RUN_MAINTENANCE_IF_MAIN;
|
Loading…
Reference in a new issue