Legoktm has uploaded a new change for review.
https://gerrit.wikimedia.org/r/177021
Change subject: Add removeInvalidEmails.php maintenance script
......................................................................
Add removeInvalidEmails.php maintenance script
The script scans the user table and removes emails
that are technically invalid which don't pass
Sanitizer::validateEmail(), and wouldn't be allowed
today. Confirmed emails are skipped entirely since
they had to be valid at some point.
Bug: T76512
Change-Id: I3cc6396ff6d8b738846b7716b4b0cddc9bf9e1a4
---
A maintenance/removeInvalidEmails.php
1 file changed, 56 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/21/177021/1
diff --git a/maintenance/removeInvalidEmails.php
b/maintenance/removeInvalidEmails.php
new file mode 100644
index 0000000..e838e1f
--- /dev/null
+++ b/maintenance/removeInvalidEmails.php
@@ -0,0 +1,56 @@
+<?php
+
+require_once __DIR__ . '/Maintenance.php';
+
+/**
+ * A script to remove emails that are invalid from
+ * the user_email column of the user table. Emails
+ * are validated before users can add them, but
+ * this was not always the case so older users may
+ * have invalid ones.
+ */
+class RemoveInvalidEmails extends Maintenance {
+ public function __construct() {
+ parent::__construct();
+ $this->setBatchSize( 500 );
+ }
+ public function execute() {
+ $dbr = $this->getDB( DB_SLAVE );
+ $dbw = $this->getDB( DB_MASTER );
+ do {
+ $rows = $dbr->select(
+ 'user',
+ array( 'user_id', 'user_email' ),
+ array( 'user_email != ""',
'user_email_authenticated IS NULL' ),
+ __METHOD__,
+ array( 'LIMIT' => $this->mBatchSize )
+ );
+ $count = $rows->numRows();
+ $badIds = array();
+ foreach ( $rows as $row ) {
+ if ( !Sanitizer::validateEmail(
$row->user_email ) ) {
+ $badIds[] = $row->user_id;
+ }
+ }
+
+ if ( $badIds ) {
+ $badCount = count( $badIds );
+ $this->output( "Removing $badCount emails from
the database.\n" );
+ $dbw->update(
+ 'user',
+ array( 'user_email' => '' ),
+ array( 'user_id' => $badIds ),
+ __METHOD__
+ );
+ foreach ( $badIds as $badId ) {
+ User::newFromId( $badId
)->invalidateCache();
+ }
+ wfWaitForSlaves();
+ }
+ } while ( $count !== 0 );
+ $this->output( "Done.\n" );
+ }
+}
+
+$maintClass = 'RemoveInvalidEmails';
+require_once RUN_MAINTENANCE_IF_MAIN;
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/177021
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3cc6396ff6d8b738846b7716b4b0cddc9bf9e1a4
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits