BryanDavis has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/387161 )

Change subject: Add invalidateEmail maintenance script
......................................................................

Add invalidateEmail maintenance script

Add a maintenance script that can be used to invalidate the email
address of a list of users. Users receive the same echo notification
that they would receive if invalidated due to excessive bounces.

Bug: T152147
Change-Id: I7dbe51218fab7aeb74933c809a2f7ff830e07d1d
---
M .phpcs.xml
A maintenance/invalidateEmail.php
2 files changed, 80 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BounceHandler 
refs/changes/61/387161/1

diff --git a/.phpcs.xml b/.phpcs.xml
index af73563..e0057e0 100644
--- a/.phpcs.xml
+++ b/.phpcs.xml
@@ -6,6 +6,9 @@
                <exclude 
name="MediaWiki.NamingConventions.LowerCamelFunctionsName.FunctionName" />
                <exclude 
name="MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment.NewLineComment" />
        </rule>
+    <rule ref="MediaWiki.Files.ClassMatchesFilename.WrongCase">
+        <exclude-pattern>*/maintenance/*</exclude-pattern>
+    </rule>
        <file>.</file>
        <arg name="extensions" value="php,php5,inc" />
        <arg name="encoding" value="UTF-8" />
diff --git a/maintenance/invalidateEmail.php b/maintenance/invalidateEmail.php
new file mode 100644
index 0000000..9fb5dd6
--- /dev/null
+++ b/maintenance/invalidateEmail.php
@@ -0,0 +1,77 @@
+<?php
+/**
+ * @section LICENSE
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+$IP = getenv( 'MW_INSTALL_PATH' );
+if ( $IP === false ) {
+       $IP = __DIR__ . '/../../..';
+}
+require_once "$IP/maintenance/Maintenance.php";
+
+/**
+ * @copyright © 2017 Wikimedia Foundation and contributors.
+ */
+class InvalidateEmail extends Maintenance {
+       public function __construct() {
+               parent::__construct();
+               $this->requireExtension( 'BounceHandler' );
+               $this->mDescription =
+                       "Invalidate a user's email address and leave them a 
message.";
+               $this->addOption( 'userlist',
+                       'List of usernames to invalidate, one per line', true, 
true );
+       }
+
+       public function execute() {
+               $list = $this->getOption( 'userlist' );
+               if ( !is_file( $list ) ) {
+                       $this->output( "ERROR - File not found: {$list}" );
+                       exit( 1 );
+               }
+               $file = fopen( $list, 'r' );
+               if ( $file === false ) {
+                       $this->output( "ERROR - Could not open file: {$list}" );
+                       exit( 1 );
+               }
+               $bounce = new BounceHandlerActions(
+                       wfWikiID(), 0, 0, false, 'Email invalidated manually.' 
);
+               // @codingStandardsIgnoreStart
+               while ( strlen( $username = trim( fgets( $file ) ) ) ) {
+               // @codingStandardsIgnoreEnd
+                       $this->output( "Invalidate email for: {$username}\n" );
+                       $user = User::newFromName( $username );
+                       if ( $user && $user->getId() ) {
+                               $bounce->unSubscribeUser(
+                                       [
+                                               'rawEmail' => $user->getEmail(),
+                                               'rawUserId' => $user->getId(),
+                                       ],
+                                       [ /* Headers intentionally blank */ ]
+                               );
+                       } else {
+                               $this->output( "ERROR - Unknown user 
{$username}\n" );
+                       }
+               }
+               fclose( $file );
+               $this->output( "done.\n" );
+       }
+}
+
+$maintClass = "InvalidateEmail";
+require_once RUN_MAINTENANCE_IF_MAIN;

-- 
To view, visit https://gerrit.wikimedia.org/r/387161
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7dbe51218fab7aeb74933c809a2f7ff830e07d1d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BounceHandler
Gerrit-Branch: master
Gerrit-Owner: BryanDavis <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to