Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
20 / 20 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| CheckUsernames | |
100.00% |
20 / 20 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| execute | |
100.00% |
17 / 17 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Check that database usernames are actually valid. |
| 4 | * |
| 5 | * @license GPL-2.0-or-later |
| 6 | * @file |
| 7 | * @ingroup Maintenance |
| 8 | */ |
| 9 | |
| 10 | use MediaWiki\Maintenance\Maintenance; |
| 11 | |
| 12 | // @codeCoverageIgnoreStart |
| 13 | require_once __DIR__ . '/Maintenance.php'; |
| 14 | // @codeCoverageIgnoreEnd |
| 15 | |
| 16 | /** |
| 17 | * Maintenance script to check that database usernames are actually valid. |
| 18 | * |
| 19 | * An existing usernames can become invalid if UserNameUtils::isValid() |
| 20 | * is altered or if we change the $wgMaxNameChars |
| 21 | * |
| 22 | * @ingroup Maintenance |
| 23 | */ |
| 24 | class CheckUsernames extends Maintenance { |
| 25 | |
| 26 | public function __construct() { |
| 27 | parent::__construct(); |
| 28 | $this->addDescription( 'Verify that database usernames are actually valid' ); |
| 29 | $this->setBatchSize( 1000 ); |
| 30 | } |
| 31 | |
| 32 | public function execute() { |
| 33 | $dbr = $this->getReplicaDB(); |
| 34 | $userNameUtils = $this->getServiceContainer()->getUserNameUtils(); |
| 35 | |
| 36 | $maxUserId = 0; |
| 37 | do { |
| 38 | $res = $dbr->newSelectQueryBuilder() |
| 39 | ->select( [ 'user_id', 'user_name' ] ) |
| 40 | ->from( 'user' ) |
| 41 | ->where( $dbr->expr( 'user_id', '>', $maxUserId ) ) |
| 42 | ->orderBy( 'user_id' ) |
| 43 | ->limit( $this->getBatchSize() ) |
| 44 | ->caller( __METHOD__ ) |
| 45 | ->fetchResultSet(); |
| 46 | |
| 47 | foreach ( $res as $row ) { |
| 48 | if ( !$userNameUtils->isValid( $row->user_name ) ) { |
| 49 | $this->output( sprintf( "Found: %6d: '%s'\n", $row->user_id, $row->user_name ) ); |
| 50 | wfDebugLog( 'checkUsernames', $row->user_name ); |
| 51 | } |
| 52 | } |
| 53 | // @phan-suppress-next-line PhanPossiblyUndeclaredVariable $res has at at least one item |
| 54 | $maxUserId = $row->user_id; |
| 55 | } while ( $res->numRows() ); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | // @codeCoverageIgnoreStart |
| 60 | $maintClass = CheckUsernames::class; |
| 61 | require_once RUN_MAINTENANCE_IF_MAIN; |
| 62 | // @codeCoverageIgnoreEnd |