MediaWiki master
deleteUserEmail.php
Go to the documentation of this file.
1<?php
29
30// @codeCoverageIgnoreStart
31require_once __DIR__ . '/Maintenance.php';
32// @codeCoverageIgnoreEnd
33
39 public function __construct() {
40 parent::__construct();
41 $this->addDescription( "Delete a user's email" );
42 $this->addArg( 'user', 'Username or user ID, if starts with #', true );
43 }
44
45 public function execute() {
46 $userFactory = $this->getServiceContainer()->getUserFactory();
47 $userName = $this->getArg( 0 );
48 if ( preg_match( '/^#\d+$/', $userName ) ) {
49 $user = $userFactory->newFromId( (int)substr( $userName, 1 ) );
50 } else {
51 $user = $userFactory->newFromName( $userName );
52 }
53
54 // Checking whether User object is valid and has an actual id
55 if ( !$user || !$user->isRegistered() || !$user->loadFromId() ) {
56 $this->fatalError( "Error: user '$userName' could not be loaded" );
57 }
58
59 // Blank the email address
60 $user->invalidateEmail();
61 $user->saveSettings();
62 $this->output( "Done!\n" );
63 }
64}
65
66// @codeCoverageIgnoreStart
67$maintClass = DeleteUserEmail::class;
68require_once RUN_MAINTENANCE_IF_MAIN;
69// @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