MediaWiki master
deleteUserEmail.php
Go to the documentation of this file.
1<?php
28require_once __DIR__ . '/Maintenance.php';
29
36 public function __construct() {
37 parent::__construct();
38 $this->addDescription( "Delete a user's email" );
39 $this->addArg( 'user', 'Username or user ID, if starts with #', true );
40 }
41
42 public function execute() {
43 $userFactory = $this->getServiceContainer()->getUserFactory();
44 $userName = $this->getArg( 0 );
45 if ( preg_match( '/^#\d+$/', $userName ) ) {
46 $user = $userFactory->newFromId( (int)substr( $userName, 1 ) );
47 } else {
48 $user = $userFactory->newFromName( $userName );
49 }
50
51 // Checking whether User object is valid and has an actual id
52 if ( !$user || !$user->isRegistered() || !$user->loadFromId() ) {
53 $this->fatalError( "Error: user '$userName' could not be loaded" );
54 }
55
56 // Blank the email address
57 $user->invalidateEmail();
58 $user->saveSettings();
59 $this->output( "Done!\n" );
60 }
61}
62
63$maintClass = DeleteUserEmail::class;
64require_once RUN_MAINTENANCE_IF_MAIN;
execute()
Do the actual work.
__construct()
Default constructor.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
addArg( $arg, $description, $required=true, $multi=false)
Add some args that are needed.
output( $out, $channel=null)
Throw some output to the user.
getServiceContainer()
Returns the main service container.
getArg( $argId=0, $default=null)
Get an argument.
addDescription( $text)
Set the description text.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
$maintClass