Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 40 |
|
0.00% |
0 / 9 |
CRAP | |
0.00% |
0 / 1 |
UsersToRenameDatabaseUpdates | |
0.00% |
0 / 40 |
|
0.00% |
0 / 9 |
132 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
updateStatus | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
markNotified | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
markRenamed | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
markRedirectSkipped | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
remove | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
insert | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
batchInsert | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
12 | |||
findUsers | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\CentralAuth\UsersToRename; |
4 | |
5 | use Wikimedia\Rdbms\IDatabase; |
6 | use Wikimedia\Rdbms\IResultWrapper; |
7 | |
8 | class UsersToRenameDatabaseUpdates { |
9 | |
10 | /** |
11 | * Notified via talk page |
12 | */ |
13 | public const NOTIFIED = 4; |
14 | /** |
15 | * A redirect, temporarily skipped |
16 | */ |
17 | private const REDIRECT = 5; |
18 | /** |
19 | * Renamed! |
20 | */ |
21 | private const RENAMED = 8; |
22 | |
23 | private IDatabase $db; |
24 | |
25 | public function __construct( IDatabase $db ) { |
26 | $this->db = $db; |
27 | } |
28 | |
29 | /** |
30 | * @param string $name |
31 | * @param string $wiki |
32 | * @param int $status |
33 | */ |
34 | protected function updateStatus( $name, $wiki, $status ) { |
35 | $this->db->newUpdateQueryBuilder() |
36 | ->update( 'users_to_rename' ) |
37 | ->set( [ 'utr_status' => $status ] ) |
38 | ->where( [ 'utr_wiki' => $wiki, 'utr_name' => $name ] ) |
39 | ->caller( __METHOD__ ) |
40 | ->execute(); |
41 | } |
42 | |
43 | /** |
44 | * @param string $name |
45 | * @param string $wiki |
46 | */ |
47 | public function markNotified( $name, $wiki ) { |
48 | $this->updateStatus( $name, $wiki, self::NOTIFIED ); |
49 | } |
50 | |
51 | /** |
52 | * @param string $name |
53 | * @param string $wiki |
54 | */ |
55 | public function markRenamed( $name, $wiki ) { |
56 | $this->updateStatus( $name, $wiki, self::RENAMED ); |
57 | } |
58 | |
59 | /** |
60 | * @param string $name |
61 | * @param string $wiki |
62 | */ |
63 | public function markRedirectSkipped( $name, $wiki ) { |
64 | $this->updateStatus( $name, $wiki, self::REDIRECT ); |
65 | } |
66 | |
67 | /** |
68 | * @param string $name |
69 | * @param string $wiki |
70 | */ |
71 | public function remove( $name, $wiki ) { |
72 | $this->db->newDeleteQueryBuilder() |
73 | ->deleteFrom( 'users_to_rename' ) |
74 | ->where( [ 'utr_wiki' => $wiki, 'utr_name' => $name ] ) |
75 | ->caller( __METHOD__ ) |
76 | ->execute(); |
77 | } |
78 | |
79 | /** |
80 | * @param string $name |
81 | * @param string $wiki |
82 | */ |
83 | public function insert( $name, $wiki ) { |
84 | $this->batchInsert( [ [ |
85 | 'name' => $name, |
86 | 'wiki' => $wiki |
87 | ] ] ); |
88 | } |
89 | |
90 | /** |
91 | * Batch insert rows |
92 | * |
93 | * @param array[] $info Array with array members that have 'name' and 'wiki' keys |
94 | */ |
95 | public function batchInsert( array $info ) { |
96 | if ( !$info ) { |
97 | return; |
98 | } |
99 | |
100 | $rows = []; |
101 | foreach ( $info as $row ) { |
102 | $rows[] = [ |
103 | 'utr_name' => $row['name'], |
104 | 'utr_wiki' => $row['wiki'], |
105 | ]; |
106 | } |
107 | |
108 | $this->db->newInsertQueryBuilder() |
109 | ->insertInto( 'users_to_rename' ) |
110 | ->ignore() |
111 | ->rows( $rows ) |
112 | ->caller( __METHOD__ ) |
113 | ->execute(); |
114 | } |
115 | |
116 | /** |
117 | * @param string $wiki |
118 | * @param int $status |
119 | * @param int $limit |
120 | * |
121 | * @return IResultWrapper |
122 | */ |
123 | public function findUsers( $wiki, $status, $limit ) { |
124 | // @todo this shouldn't return prefixed field names |
125 | return $this->db->newSelectQueryBuilder() |
126 | ->select( [ 'utr_name', 'utr_wiki' ] ) |
127 | ->from( 'users_to_rename' ) |
128 | ->where( [ 'utr_status' => $status, 'utr_wiki' => $wiki ] ) |
129 | ->limit( $limit ) |
130 | ->caller( __METHOD__ ) |
131 | ->fetchResultSet(); |
132 | } |
133 | } |