From: jenkins-bot Date: Wed, 3 Dec 2014 21:11:00 +0000 (+0000) Subject: Merge "Add removeInvalidEmails.php maintenance script" X-Git-Tag: 1.31.0-rc.0~13106 X-Git-Url: http://git.cyclocoop.org/%7B%7B%20url_for%28%27admin_vote_add%27%29%20%7D%7D?a=commitdiff_plain;h=230444c9af075ff2b4908388a83d18497f9a9dd4;hp=b7c79a9dc0fd5b38de7030fdc3a1a1befda799d4;p=lhc%2Fweb%2Fwiklou.git Merge "Add removeInvalidEmails.php maintenance script" --- diff --git a/maintenance/removeInvalidEmails.php b/maintenance/removeInvalidEmails.php new file mode 100644 index 0000000000..7ff69a1fec --- /dev/null +++ b/maintenance/removeInvalidEmails.php @@ -0,0 +1,78 @@ +addOption( 'commit', 'Whether to actually update the database', false, false ); + $this->setBatchSize( 500 ); + } + public function execute() { + $this->commit = $this->hasOption( 'commit' ); + $dbr = $this->getDB( DB_SLAVE ); + $dbw = $this->getDB( DB_MASTER ); + $lastId = 0; + do { + $rows = $dbr->select( + 'user', + array( 'user_id', 'user_email' ), + array( + 'user_id > ' . $dbr->addQuotes( $lastId ), + 'user_email != ""', + 'user_email_authenticated IS NULL' + ), + __METHOD__, + array( 'LIMIT' => $this->mBatchSize ) + ); + $count = $rows->numRows(); + $badIds = array(); + foreach ( $rows as $row ) { + if ( !Sanitizer::validateEmail( trim( $row->user_email ) ) ) { + $this->output( "Found bad email: {$row->user_email} for user #{$row->user_id}\n" ); + $badIds[] = $row->user_id; + if ( $row->user_id > $lastId ) { + $lastId = $row->user_id; + } + } + } + + if ( $badIds ) { + $badCount = count( $badIds ); + if ( $this->commit ) { + $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(); + } else { + $this->output( "Would have removed $badCount emails from the database.\n" ); + + } + } + } while ( $count !== 0 ); + $this->output( "Done.\n" ); + } +} + +$maintClass = 'RemoveInvalidEmails'; +require_once RUN_MAINTENANCE_IF_MAIN;