32 $this->commit = $this->hasOption(
'commit' );
33 $dbr = $this->getReplicaDB();
34 $dbw = $this->getPrimaryDB();
37 $rows = $dbr->newSelectQueryBuilder()
38 ->select( [
'user_id',
'user_email' ] )
41 $dbr->expr(
'user_id',
'>', $lastId ),
42 $dbr->expr(
'user_email',
'!=',
'' ),
43 'user_email_authenticated' =>
null,
45 ->limit( $this->getBatchSize() )
46 ->caller( __METHOD__ )->fetchResultSet();
47 $count = $rows->numRows();
49 foreach ( $rows as $row ) {
50 if ( !Sanitizer::validateEmail( trim( $row->user_email ) ) ) {
51 $this->output(
"Found bad email: {$row->user_email} for user #{$row->user_id}\n" );
52 $badIds[] = $row->user_id;
54 if ( $row->user_id > $lastId ) {
55 $lastId = $row->user_id;
60 $badCount = count( $badIds );
61 if ( $this->commit ) {
62 $this->output(
"Removing $badCount emails from the database.\n" );
63 $dbw->newUpdateQueryBuilder()
65 ->set( [
'user_email' =>
'' ] )
66 ->where( [
'user_id' => $badIds ] )
67 ->caller( __METHOD__ )
69 foreach ( $badIds as $badId ) {
70 User::newFromId( $badId )->invalidateCache();
72 $this->waitForReplication();
74 $this->output(
"Would have removed $badCount emails from the database.\n" );
78 }
while ( $count !== 0 );
79 $this->output(
"Done.\n" );