Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 32 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
ForeignDBRepo | |
0.00% |
0 / 32 |
|
0.00% |
0 / 6 |
56 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
2 | |||
getPrimaryDB | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
getReplicaDB | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getDBFactory | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
2 | |||
assertWritableRepo | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getBlobStore | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * A foreign repository with an accessible MediaWiki database. |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License as published by |
7 | * the Free Software Foundation; either version 2 of the License, or |
8 | * (at your option) any later version. |
9 | * |
10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * GNU General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU General Public License along |
16 | * with this program; if not, write to the Free Software Foundation, Inc., |
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
18 | * http://www.gnu.org/copyleft/gpl.html |
19 | * |
20 | * @file |
21 | * @ingroup FileRepo |
22 | */ |
23 | |
24 | use MediaWiki\MediaWikiServices; |
25 | use MediaWiki\Storage\BlobStore; |
26 | use Wikimedia\Rdbms\DatabaseDomain; |
27 | use Wikimedia\Rdbms\IDatabase; |
28 | |
29 | /** |
30 | * A foreign repository with an accessible MediaWiki database |
31 | * |
32 | * @ingroup FileRepo |
33 | */ |
34 | class ForeignDBRepo extends LocalRepo implements IForeignRepoWithDB { |
35 | /** @var string */ |
36 | protected $dbType; |
37 | |
38 | /** @var string */ |
39 | protected $dbServer; |
40 | |
41 | /** @var string */ |
42 | protected $dbUser; |
43 | |
44 | /** @var string */ |
45 | protected $dbPassword; |
46 | |
47 | /** @var string */ |
48 | protected $dbName; |
49 | |
50 | /** @var string */ |
51 | protected $dbFlags; |
52 | |
53 | /** @var string */ |
54 | protected $tablePrefix; |
55 | |
56 | /** @var IDatabase */ |
57 | protected $dbConn; |
58 | |
59 | /** @var callable */ |
60 | protected $fileFactory = [ ForeignDBFile::class, 'newFromTitle' ]; |
61 | /** @var callable */ |
62 | protected $fileFromRowFactory = [ ForeignDBFile::class, 'newFromRow' ]; |
63 | |
64 | /** |
65 | * @param array|null $info |
66 | */ |
67 | public function __construct( $info ) { |
68 | parent::__construct( $info ); |
69 | |
70 | '@phan-var array $info'; |
71 | $this->dbType = $info['dbType']; |
72 | $this->dbServer = $info['dbServer']; |
73 | $this->dbUser = $info['dbUser']; |
74 | $this->dbPassword = $info['dbPassword']; |
75 | $this->dbName = $info['dbName']; |
76 | $this->dbFlags = $info['dbFlags']; |
77 | $this->tablePrefix = $info['tablePrefix']; |
78 | $this->hasAccessibleSharedCache = $info['hasSharedCache']; |
79 | |
80 | $dbDomain = new DatabaseDomain( $this->dbName, null, $this->tablePrefix ); |
81 | $this->dbDomain = $dbDomain->getId(); |
82 | } |
83 | |
84 | public function getPrimaryDB() { |
85 | if ( !$this->dbConn ) { |
86 | $func = $this->getDBFactory(); |
87 | $this->dbConn = $func( DB_PRIMARY ); |
88 | } |
89 | |
90 | return $this->dbConn; |
91 | } |
92 | |
93 | public function getReplicaDB() { |
94 | return $this->getPrimaryDB(); |
95 | } |
96 | |
97 | /** |
98 | * @return Closure |
99 | */ |
100 | protected function getDBFactory() { |
101 | $type = $this->dbType; |
102 | $params = [ |
103 | 'host' => $this->dbServer, |
104 | 'user' => $this->dbUser, |
105 | 'password' => $this->dbPassword, |
106 | 'dbname' => $this->dbName, |
107 | 'flags' => $this->dbFlags, |
108 | 'tablePrefix' => $this->tablePrefix |
109 | ]; |
110 | |
111 | return static function ( $index ) use ( $type, $params ) { |
112 | $factory = MediaWikiServices::getInstance()->getDatabaseFactory(); |
113 | return $factory->create( $type, $params ); |
114 | }; |
115 | } |
116 | |
117 | /** |
118 | * @return never |
119 | */ |
120 | protected function assertWritableRepo() { |
121 | throw new LogicException( static::class . ': write operations are not supported.' ); |
122 | } |
123 | |
124 | public function getBlobStore(): ?BlobStore { |
125 | return null; |
126 | } |
127 | } |