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
21 use MediaWiki\MediaWikiServices
;
22 use Wikimedia\Rdbms\IConnectionProvider
;
25 * A foreign repository with a MediaWiki database accessible via the configured LBFactory.
29 class ForeignDBViaLBRepo
extends LocalRepo
implements IForeignRepoWithDB
{
31 protected $fileFactory = [ ForeignDBFile
::class, 'newFromTitle' ];
34 protected $fileFromRowFactory = [ ForeignDBFile
::class, 'newFromRow' ];
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
);
57 protected function getDBFactory() {
58 return function ( $index ) {
59 if ( $index == DB_PRIMARY
) {
60 return $this->getDbProvider()->getPrimaryDatabase( $this->dbDomain
);
62 return $this->getDbProvider()->getReplicaDatabase( $this->dbDomain
);
68 * @return IConnectionProvider
70 protected function getDbProvider(): IConnectionProvider
{
71 return MediaWikiServices
::getInstance()->getConnectionProvider();
77 protected function assertWritableRepo() {
78 throw new LogicException( static::class . ': write operations are not supported.' );
81 public function getInfo() {
82 return FileRepo
::getInfo();