Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 40 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
CentralAuthUserArrayFromResult | |
0.00% |
0 / 40 |
|
0.00% |
0 / 2 |
72 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
20 | |||
setCurrent | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
20 |
1 | <?php |
2 | /** |
3 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | * |
18 | * @file |
19 | */ |
20 | |
21 | namespace MediaWiki\Extension\CentralAuth\User; |
22 | |
23 | use MediaWiki\Extension\CentralAuth\CentralAuthServices; |
24 | use MediaWiki\User\UserArrayFromResult; |
25 | use MediaWiki\WikiMap\WikiMap; |
26 | use stdClass; |
27 | use Wikimedia\Rdbms\IResultWrapper; |
28 | |
29 | class CentralAuthUserArrayFromResult extends UserArrayFromResult { |
30 | /** @var stdClass[] */ |
31 | private $globalData; |
32 | |
33 | /** |
34 | * @param IResultWrapper $res |
35 | */ |
36 | public function __construct( IResultWrapper $res ) { |
37 | parent::__construct( $res ); |
38 | |
39 | if ( $res->numRows() == 0 ) { |
40 | return; |
41 | } |
42 | |
43 | /** |
44 | * Load global user data |
45 | */ |
46 | $names = []; |
47 | foreach ( $res as $row ) { |
48 | $names[] = $row->user_name; |
49 | } |
50 | $res->rewind(); |
51 | |
52 | $dbr = CentralAuthServices::getDatabaseManager()->getCentralReplicaDB(); |
53 | $caRes = $dbr->select( |
54 | [ 'localuser', 'globaluser', 'renameuser_status' ], |
55 | '*', |
56 | [ |
57 | 'gu_name' => $names, |
58 | 'lu_name=gu_name', |
59 | 'lu_wiki' => WikiMap::getCurrentWikiId() |
60 | ], |
61 | __METHOD__, |
62 | [], |
63 | [ |
64 | 'renameuser_status' => [ 'LEFT OUTER JOIN', 'ru_oldname=gu_name OR ru_newname=gu_name' ] |
65 | ] |
66 | ); |
67 | $this->globalData = []; |
68 | foreach ( $caRes as $row ) { |
69 | $this->globalData[$row->gu_name] = $row; |
70 | } |
71 | wfDebug( __METHOD__ . ': got user data for ' . implode( ', ', |
72 | array_keys( $this->globalData ) ) . "\n" ); |
73 | } |
74 | |
75 | /** |
76 | * @param stdClass|bool $row |
77 | */ |
78 | public function setCurrent( $row ) { |
79 | parent::setCurrent( $row ); |
80 | |
81 | if ( $row !== false ) { |
82 | if ( isset( $this->globalData[$row->user_name] ) ) { |
83 | $caRow = $this->globalData[$row->user_name]; |
84 | |
85 | // Like taken from GlobalRenameUserStatus::getNames |
86 | $renameUser = []; |
87 | if ( $caRow->ru_oldname ) { |
88 | $renameUser = [ $caRow->ru_oldname, $caRow->ru_newname ]; |
89 | } |
90 | |
91 | CentralAuthUser::setInstance( |
92 | $this->current, CentralAuthUser::newFromRow( $caRow, $renameUser ) |
93 | ); |
94 | } else { |
95 | CentralAuthUser::setInstance( |
96 | $this->current, CentralAuthUser::newUnattached( $row->user_name ) |
97 | ); |
98 | } |
99 | } |
100 | } |
101 | } |