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