2017-08-23 14:38:58 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Update the Per User Blocklist from Usernames to User Ids.
|
|
|
|
*
|
|
|
|
* @ingroup Maintenance
|
|
|
|
*/
|
2019-04-17 12:12:56 +00:00
|
|
|
|
2023-12-11 15:33:08 +00:00
|
|
|
use MediaWiki\User\User;
|
|
|
|
|
2017-08-23 14:38:58 +00:00
|
|
|
require_once getenv( 'MW_INSTALL_PATH' ) !== false
|
|
|
|
? getenv( 'MW_INSTALL_PATH' ) . '/maintenance/Maintenance.php'
|
|
|
|
: __DIR__ . '/../../../maintenance/Maintenance.php';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maintenance script that changes the usernames to ids.
|
|
|
|
*
|
|
|
|
* @ingroup Maintenance
|
|
|
|
*/
|
|
|
|
class EchoUpdatePerUserBlacklist extends LoggedUpdateMaintenance {
|
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->addDescription( 'Update echo-notifications-blacklist User Preference from Usernames to Ids' );
|
|
|
|
$this->setBatchSize( 100 );
|
|
|
|
$this->requireExtension( 'Echo' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getUpdateKey() {
|
|
|
|
return __CLASS__;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function doDBUpdates() {
|
2021-05-03 07:28:02 +00:00
|
|
|
$dbw = $this->getDB( DB_PRIMARY );
|
2019-04-17 12:12:56 +00:00
|
|
|
$dbr = $this->getDB( DB_REPLICA );
|
2017-08-23 14:38:58 +00:00
|
|
|
$iterator = new BatchRowIterator(
|
|
|
|
$dbr,
|
|
|
|
'user_properties',
|
|
|
|
[ 'up_user', 'up_property' ],
|
2020-12-17 18:27:43 +00:00
|
|
|
$this->getBatchSize()
|
2017-08-23 14:38:58 +00:00
|
|
|
);
|
|
|
|
$iterator->setFetchColumns( [
|
|
|
|
'up_user',
|
|
|
|
'up_value'
|
|
|
|
] );
|
|
|
|
$iterator->addConditions( [
|
|
|
|
'up_property' => 'echo-notifications-blacklist'
|
|
|
|
] );
|
|
|
|
|
2020-09-05 02:02:17 +00:00
|
|
|
$iterator->setCaller( __METHOD__ );
|
|
|
|
|
2017-08-23 14:38:58 +00:00
|
|
|
$this->output( "Updating Echo Notification Blacklist...\n" );
|
|
|
|
|
2023-11-09 20:16:38 +00:00
|
|
|
$centralIdLookup = $this->getServiceContainer()->getCentralIdLookup();
|
2017-08-23 14:38:58 +00:00
|
|
|
$processed = 0;
|
|
|
|
foreach ( $iterator as $batch ) {
|
|
|
|
foreach ( $batch as $row ) {
|
|
|
|
if ( !$row->up_value ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$value = explode( "\n", $row->up_value );
|
2021-05-04 16:06:42 +00:00
|
|
|
$names = array_filter( $value, static function ( $item ) {
|
2017-08-23 14:38:58 +00:00
|
|
|
return !is_numeric( $item );
|
|
|
|
} );
|
|
|
|
|
|
|
|
// If all of the values are numeric then the user has already been
|
|
|
|
// converted.
|
|
|
|
if ( !$names ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$user = User::newFromId( $row->up_user );
|
2021-06-24 19:21:49 +00:00
|
|
|
$ids = $centralIdLookup->centralIdsFromNames( $names, $user );
|
2017-08-23 14:38:58 +00:00
|
|
|
|
2024-04-13 18:33:56 +00:00
|
|
|
$dbw->newUpdateQueryBuilder()
|
|
|
|
->update( 'user_properties' )
|
|
|
|
->set( [
|
2017-10-16 22:14:31 +00:00
|
|
|
'up_value' => implode( "\n", $ids ),
|
2024-04-13 18:33:56 +00:00
|
|
|
] )
|
|
|
|
->where( [
|
2017-08-23 14:38:58 +00:00
|
|
|
'up_user' => $row->up_user,
|
|
|
|
'up_property' => 'echo-notifications-blacklist',
|
2024-04-13 18:33:56 +00:00
|
|
|
] )
|
|
|
|
->caller( __METHOD__ )
|
|
|
|
->execute();
|
2017-08-23 14:38:58 +00:00
|
|
|
$processed += $dbw->affectedRows();
|
2024-02-03 01:52:49 +00:00
|
|
|
$this->waitForReplication();
|
2017-08-23 14:38:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->output( "Updated $processed Users\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-19 10:42:30 +00:00
|
|
|
$maintClass = EchoUpdatePerUserBlacklist::class;
|
2017-08-23 14:38:58 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|