Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
90.91% covered (success)
90.91%
10 / 11
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
SendPasswordResetEmailUpdate
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 doUpdate
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2/**
3 * Send an email to reset the password
4 *
5 * @license GPL-2.0-or-later
6 * @file
7 */
8
9namespace MediaWiki\Deferred;
10
11use MediaWiki\Auth\AuthManager;
12use MediaWiki\Logger\LoggerFactory;
13
14/**
15 * Sends emails to all accounts associated with that email to reset the password
16 * @since 1.35
17 */
18class SendPasswordResetEmailUpdate implements DeferrableUpdate {
19    /** @var AuthManager */
20    private $authManager;
21
22    /** @var array */
23    private $reqs;
24
25    /** @var array */
26    private $logContext;
27
28    /**
29     * @param AuthManager $authManager
30     * @param array $reqs
31     * @param array $logContext
32     */
33    public function __construct( AuthManager $authManager, array $reqs, array $logContext ) {
34        $this->authManager = $authManager;
35        $this->reqs = $reqs;
36        $this->logContext = $logContext;
37    }
38
39    public function doUpdate() {
40        $logger = LoggerFactory::getInstance( 'authentication' );
41        foreach ( $this->reqs as $req ) {
42            // This is adding a new temporary password, not intentionally changing anything
43            // (even though it might technically invalidate an old temporary password).
44            $this->authManager->changeAuthenticationData( $req, /* $isAddition */ true );
45            $logger->info(
46                "{requestingUser} did password reset of {targetUser} and an email was sent",
47                $this->logContext + [ 'targetUser' => $req->username ]
48            );
49        }
50    }
51
52}
53
54/** @deprecated class alias since 1.42 */
55class_alias( SendPasswordResetEmailUpdate::class, 'SendPasswordResetEmailUpdate' );