Hello jenkins-bot, Dbarratt, I'd like you to do a code review. Please visit
https://gerrit.wikimedia.org/r/382521 to review the following change. Change subject: Revert "Use User Ids instead of User Names for Echo Mute" ...................................................................... Revert "Use User Ids instead of User Names for Echo Mute" This reverts commit 51d83fb7fedcd1e3327bab972f56e24f802ba0fe. Change-Id: I1387e9132a1575305b05ba7efaab387737e95002 --- M Hooks.php M extension.json M includes/ContainmentSet.php D maintenance/updatePerUserBlacklist.php 4 files changed, 5 insertions(+), 131 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo refs/changes/21/382521/1 diff --git a/Hooks.php b/Hooks.php index 4a7c06a..8e3db35 100644 --- a/Hooks.php +++ b/Hooks.php @@ -490,15 +490,10 @@ } if ( $wgEchoPerUserBlacklist ) { - $lookup = CentralIdLookup::factory(); - $ids = $user->getOption( 'echo-notifications-blacklist', [] ); - $names = $ids ? $lookup->namesFromCentralIds( $ids, $user ) : []; - $preferences['echo-notifications-blacklist'] = [ 'type' => 'usersmultiselect', 'label-message' => 'echo-pref-notifications-blacklist', 'section' => 'echo/blocknotificationslist', - 'default' => implode( "\n", $names ) ]; } @@ -1257,10 +1252,6 @@ $options['echo-subscriptions-email-edit-user-talk'] = $options['enotifusertalkpages']; } - if ( isset( $options['echo-notifications-blacklist'] ) ) { - $options['echo-notifications-blacklist'] = array_map( 'intval', explode( "\n", $options['echo-notifications-blacklist'] ) ); - } - return true; } @@ -1277,28 +1268,6 @@ if ( isset( $options['echo-subscriptions-email-edit-user-talk'] ) ) { $options['enotifusertalkpages'] = $options['echo-subscriptions-email-edit-user-talk']; unset( $options['echo-subscriptions-email-edit-user-talk'] ); - } - - // Convert usernames to ids. - if ( isset( $options['echo-notifications-blacklist'] ) ) { - if ( $options['echo-notifications-blacklist'] ) { - $value = $options['echo-notifications-blacklist']; - // Notification Blacklist may be an array of ids or a string of new line - // delimnated user names. - if ( is_array( $value ) ) { - $ids = array_filter( $value, 'is_numeric' ); - } else { - $lookup = CentralIdLookup::factory(); - $names = explode( "\n", $value ); - $ids = $lookup->centralIdsFromNames( $names, $user ); - } - - $user->setOption( 'echo-notifications-blacklist', $ids ); - $options['echo-notifications-blacklist'] = implode( "\n", $user->getOption( 'echo-notifications-blacklist' ) ); - } else { - // If the blacklist is empty, set it to null rather than an empty string. - $options['echo-notifications-blacklist'] = null; - } } return true; diff --git a/extension.json b/extension.json index dc21551..39606db 100644 --- a/extension.json +++ b/extension.json @@ -1019,7 +1019,6 @@ "SpecialNotificationsMarkRead": "includes/special/SpecialNotificationsMarkRead.php", "SuppressionMaintenanceTest": "tests/phpunit/maintenance/SupressionMaintenanceTest.php", "TestDiscussionParser": "maintenance/testDiscussionParser.php", - "UpdateEchoSchemaForSuppression": "maintenance/updateEchoSchemaForSuppression.php", - "EchoUpdatePerUserBlacklist": "maintenance/updatePerUserBlacklist.php" + "UpdateEchoSchemaForSuppression": "maintenance/updateEchoSchemaForSuppression.php" } } diff --git a/includes/ContainmentSet.php b/includes/ContainmentSet.php index d5cfff5..4b6ce1f 100644 --- a/includes/ContainmentSet.php +++ b/includes/ContainmentSet.php @@ -71,12 +71,12 @@ * @param string $preferenceName */ public function addFromUserOption( $preferenceName ) { - $preference = $this->recipient->getOption( $preferenceName, [] ); + $preference = $this->recipient->getOption( $preferenceName ); if ( $preference ) { - $lookup = CentralIdLookup::factory(); - $names = $lookup->lookupCentralIds( array_flip( $preference ), $this->recipient ); - $this->addArray( array_values( $names ) ); + $items = explode( "\n", $preference ); + + $this->addArray( $items ); } } diff --git a/maintenance/updatePerUserBlacklist.php b/maintenance/updatePerUserBlacklist.php deleted file mode 100644 index 106e21a..0000000 --- a/maintenance/updatePerUserBlacklist.php +++ /dev/null @@ -1,94 +0,0 @@ -<?php -/** - * Update the Per User Blocklist from Usernames to User Ids. - * - * @ingroup Maintenance - */ -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() { - $dbFactory = MWEchoDbFactory::newFromDefault(); - $dbw = $dbFactory->getEchoDb( DB_MASTER ); - $dbr = $dbFactory->getEchoDb( DB_REPLICA ); - $iterator = new BatchRowIterator( - $dbr, - 'user_properties', - [ 'up_user', 'up_property' ], - $this->mBatchSize - ); - $iterator->setFetchColumns( [ - 'up_user', - 'up_value' - ] ); - $iterator->addConditions( [ - 'up_property' => 'echo-notifications-blacklist' - ] ); - - $this->output( "Updating Echo Notification Blacklist...\n" ); - - $lookup = CentralIdLookup::factory(); - $processed = 0; - foreach ( $iterator as $batch ) { - foreach ( $batch as $row ) { - if ( !$row->up_value ) { - continue; - } - - $value = explode( "\n", $row->up_value ); - $names = array_filter( $value, function ( $item ) { - 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 ); - $ids = $lookup->lookupUserNames( array_flip( $names ), $user ); - - $dbw->update( - 'user_properties', - [ - 'up_value' => implode( "\n", array_values( $ids ) ), - ], - [ - 'up_user' => $row->up_user, - 'up_property' => 'echo-notifications-blacklist', - ] - ); - $processed += $dbw->affectedRows(); - $dbFactory->waitForSlaves(); - } - - $this->output( "Updated $processed Users\n" ); - } - - return true; - } -} - -$maintClass = 'EchoUpdatePerUserBlacklist'; -require_once RUN_MAINTENANCE_IF_MAIN; -- To view, visit https://gerrit.wikimedia.org/r/382521 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1387e9132a1575305b05ba7efaab387737e95002 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Echo Gerrit-Branch: wmf/1.31.0-wmf.1 Gerrit-Owner: Thcipriani <tcipri...@wikimedia.org> Gerrit-Reviewer: Dbarratt <dbarr...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits