Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 7 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
DatabaseRepository | |
0.00% |
0 / 7 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
getDB | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
identifierExists | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
getTableName | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
getIdentifierField | n/a |
0 / 0 |
n/a |
0 / 0 |
0 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\OAuth\Repository; |
4 | |
5 | use MediaWiki\Extension\OAuth\Backend\Utils; |
6 | use Wikimedia\Rdbms\IDatabase; |
7 | |
8 | abstract class DatabaseRepository { |
9 | |
10 | /** |
11 | * @param int $index |
12 | * @return IDatabase |
13 | */ |
14 | public function getDB( $index = DB_REPLICA ) { |
15 | return Utils::getCentralDB( $index ); |
16 | } |
17 | |
18 | /** |
19 | * Is given identifier stored in the DB |
20 | * |
21 | * @param string $identifier |
22 | * @return bool |
23 | */ |
24 | public function identifierExists( $identifier ) { |
25 | return $this->getDB()->newSelectQueryBuilder() |
26 | ->select( $this->getIdentifierField() ) |
27 | ->from( $this->getTableName() ) |
28 | ->where( [ $this->getIdentifierField() => $identifier ] ) |
29 | ->caller( __METHOD__ ) |
30 | ->fetchRow() !== false; |
31 | } |
32 | |
33 | abstract protected function getTableName(): string; |
34 | |
35 | abstract protected function getIdentifierField(): string; |
36 | } |