MediaWiki master
deleteUserEmail.php
Go to the documentation of this file.
1<?php
15
16// @codeCoverageIgnoreStart
17require_once __DIR__ . '/Maintenance.php';
18// @codeCoverageIgnoreEnd
19
25 public function __construct() {
26 parent::__construct();
27 $this->addDescription( "Delete a user's email" );
28 $this->addArg( 'user', 'Username or user ID, if starts with #', true );
29 }
30
31 public function execute() {
32 $userFactory = $this->getServiceContainer()->getUserFactory();
33 $userName = $this->getArg( 0 );
34 if ( preg_match( '/^#\d+$/', $userName ) ) {
35 $user = $userFactory->newFromId( (int)substr( $userName, 1 ) );
36 } else {
37 $user = $userFactory->newFromName( $userName );
38 }
39
40 // Checking whether User object is valid and has an actual id
41 if ( !$user || !$user->isRegistered() || !$user->loadFromId() ) {
42 $this->fatalError( "Error: user '$userName' could not be loaded" );
43 }
44
45 // Blank the email address
46 $user->invalidateEmail();
47 $user->saveSettings();
48 $this->output( "Done!\n" );
49 }
50}
51
52// @codeCoverageIgnoreStart
53$maintClass = DeleteUserEmail::class;
54require_once RUN_MAINTENANCE_IF_MAIN;
55// @codeCoverageIgnoreEnd
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.
getArg( $argId=0, $default=null)
Get an argument.
output( $out, $channel=null)
Throw some output to the user.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.
$maintClass