8require_once __DIR__ .
'/Maintenance.php';
24 private $commit =
false;
27 parent::__construct();
28 $this->
addOption(
'commit',
'Whether to actually update the database',
false,
false );
33 $this->commit = $this->
hasOption(
'commit' );
38 $rows = $dbr->newSelectQueryBuilder()
39 ->select( [
'user_id',
'user_email' ] )
42 $dbr->expr(
'user_id',
'>', $lastId ),
43 $dbr->expr(
'user_email',
'!=',
'' ),
44 'user_email_authenticated' =>
null,
47 ->caller( __METHOD__ )->fetchResultSet();
48 $count = $rows->numRows();
50 foreach ( $rows as $row ) {
51 if ( !Sanitizer::validateEmail( trim( $row->user_email ) ) ) {
52 $this->
output(
"Found bad email: {$row->user_email} for user #{$row->user_id}\n" );
53 $badIds[] = $row->user_id;
55 if ( $row->user_id > $lastId ) {
56 $lastId = $row->user_id;
61 $badCount = count( $badIds );
62 if ( $this->commit ) {
63 $this->
output(
"Removing $badCount emails from the database.\n" );
64 $dbw->newUpdateQueryBuilder()
66 ->set( [
'user_email' =>
'' ] )
67 ->where( [
'user_id' => $badIds ] )
68 ->caller( __METHOD__ )
70 foreach ( $badIds as $badId ) {
71 User::newFromId( $badId )->invalidateCache();
75 $this->
output(
"Would have removed $badCount emails from the database.\n" );
79 }
while ( $count !== 0 );
80 $this->
output(
"Done.\n" );
86require_once RUN_MAINTENANCE_IF_MAIN;
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
getBatchSize()
Returns batch size.
output( $out, $channel=null)
Throw some output to the user.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
waitForReplication()
Wait for replica DB servers to catch up.
hasOption( $name)
Checks to see if a particular option was set.
A script to remove emails that are invalid from the user_email column of the user table.
execute()
Do the actual work.
__construct()
Default constructor.