Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / filerepo / ForeignDBViaLBRepo.php
blob25a1c7814e128c9502722db30f0cf34e2d22bce1
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.
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.
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
18 * @file
21 use MediaWiki\MediaWikiServices;
22 use Wikimedia\Rdbms\IConnectionProvider;
24 /**
25 * A foreign repository with a MediaWiki database accessible via the configured LBFactory.
27 * @ingroup FileRepo
29 class ForeignDBViaLBRepo extends LocalRepo implements IForeignRepoWithDB {
30 /** @var array */
31 protected $fileFactory = [ ForeignDBFile::class, 'newFromTitle' ];
33 /** @var array */
34 protected $fileFromRowFactory = [ ForeignDBFile::class, 'newFromRow' ];
36 /**
37 * @param array|null $info
39 public function __construct( $info ) {
40 parent::__construct( $info );
41 '@phan-var array $info';
42 $this->dbDomain = $info['wiki'];
43 $this->hasAccessibleSharedCache = $info['hasSharedCache'];
46 public function getPrimaryDB() {
47 return $this->getDbProvider()->getPrimaryDatabase( $this->dbDomain );
50 public function getReplicaDB() {
51 return $this->getDbProvider()->getReplicaDatabase( $this->dbDomain );
54 /**
55 * @return Closure
57 protected function getDBFactory() {
58 return function ( $index ) {
59 if ( $index == DB_PRIMARY ) {
60 return $this->getDbProvider()->getPrimaryDatabase( $this->dbDomain );
61 } else {
62 return $this->getDbProvider()->getReplicaDatabase( $this->dbDomain );
67 /**
68 * @return IConnectionProvider
70 protected function getDbProvider(): IConnectionProvider {
71 return MediaWikiServices::getInstance()->getConnectionProvider();
74 /**
75 * @return never
77 protected function assertWritableRepo() {
78 throw new LogicException( static::class . ': write operations are not supported.' );
81 public function getInfo() {
82 return FileRepo::getInfo();