Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
ForeignDBViaLBRepo
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 7
72
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 getPrimaryDB
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getReplicaDB
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getDBFactory
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
6
 getDbProvider
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 assertWritableRepo
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getInfo
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
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
21namespace MediaWiki\FileRepo;
22
23use Closure;
24use LogicException;
25use MediaWiki\FileRepo\File\ForeignDBFile;
26use MediaWiki\MediaWikiServices;
27use Wikimedia\Rdbms\IConnectionProvider;
28
29/**
30 * A foreign repository with a MediaWiki database accessible via the configured LBFactory.
31 *
32 * @ingroup FileRepo
33 */
34class ForeignDBViaLBRepo extends LocalRepo implements IForeignRepoWithDB {
35    /** @var array */
36    protected $fileFactory = [ ForeignDBFile::class, 'newFromTitle' ];
37
38    /** @var array */
39    protected $fileFromRowFactory = [ ForeignDBFile::class, 'newFromRow' ];
40
41    /**
42     * @param array|null $info
43     */
44    public function __construct( $info ) {
45        parent::__construct( $info );
46        '@phan-var array $info';
47        $this->dbDomain = $info['wiki'];
48        $this->hasAccessibleSharedCache = $info['hasSharedCache'];
49    }
50
51    public function getPrimaryDB() {
52        return $this->getDbProvider()->getPrimaryDatabase( $this->dbDomain );
53    }
54
55    public function getReplicaDB() {
56        return $this->getDbProvider()->getReplicaDatabase( $this->dbDomain );
57    }
58
59    /**
60     * @return Closure
61     */
62    protected function getDBFactory() {
63        return function ( $index ) {
64            if ( $index == DB_PRIMARY ) {
65                return $this->getDbProvider()->getPrimaryDatabase( $this->dbDomain );
66            } else {
67                return $this->getDbProvider()->getReplicaDatabase( $this->dbDomain );
68            }
69        };
70    }
71
72    protected function getDbProvider(): IConnectionProvider {
73        return MediaWikiServices::getInstance()->getConnectionProvider();
74    }
75
76    /**
77     * @return never
78     */
79    protected function assertWritableRepo() {
80        throw new LogicException( static::class . ': write operations are not supported.' );
81    }
82
83    public function getInfo() {
84        return FileRepo::getInfo();
85    }
86}
87
88/** @deprecated class alias since 1.44 */
89class_alias( ForeignDBViaLBRepo::class, 'ForeignDBViaLBRepo' );