MediaWiki  master
ForeignDBViaLBRepo.php
Go to the documentation of this file.
1 <?php
26 
34  protected $fileFactory = [ ForeignDBFile::class, 'newFromTitle' ];
35 
37  protected $fileFromRowFactory = [ ForeignDBFile::class, 'newFromRow' ];
38 
42  public function __construct( $info ) {
43  parent::__construct( $info );
44  '@phan-var array $info';
45  $this->dbDomain = $info['wiki'];
46  $this->hasAccessibleSharedCache = $info['hasSharedCache'];
47  }
48 
49  public function getMasterDB() {
50  return $this->getDBLoadBalancer()->getConnectionRef( DB_MASTER, [], $this->dbDomain );
51  }
52 
53  public function getReplicaDB() {
54  return $this->getDBLoadBalancer()->getConnectionRef( DB_REPLICA, [], $this->dbDomain );
55  }
56 
60  protected function getDBFactory() {
61  return function ( $index ) {
62  return $this->getDBLoadBalancer()->getConnectionRef( $index, [], $this->dbDomain );
63  };
64  }
65 
69  protected function getDBLoadBalancer() {
70  $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
71 
72  return $lbFactory->getMainLB( $this->dbDomain );
73  }
74 
75  protected function assertWritableRepo() {
76  throw new MWException( static::class . ': write operations are not supported.' );
77  }
78 
79  public function getInfo() {
80  return FileRepo::getInfo();
81  }
82 }
ForeignDBViaLBRepo\getDBFactory
getDBFactory()
Definition: ForeignDBViaLBRepo.php:60
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:172
FileRepo\getInfo
getInfo()
Return information about the repository.
Definition: FileRepo.php:1986
ForeignDBViaLBRepo\$fileFromRowFactory
array $fileFromRowFactory
Definition: ForeignDBViaLBRepo.php:37
ForeignDBViaLBRepo\getInfo
getInfo()
Return information about the repository.
Definition: ForeignDBViaLBRepo.php:79
MWException
MediaWiki exception.
Definition: MWException.php:29
ForeignDBViaLBRepo
A foreign repository with a MediaWiki database accessible via the configured LBFactory.
Definition: ForeignDBViaLBRepo.php:32
ForeignDBViaLBRepo\$fileFactory
array $fileFactory
Definition: ForeignDBViaLBRepo.php:34
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
DB_MASTER
const DB_MASTER
Definition: defines.php:26
ForeignDBViaLBRepo\getReplicaDB
getReplicaDB()
Get a connection to the replica DB.
Definition: ForeignDBViaLBRepo.php:53
ForeignDBViaLBRepo\getMasterDB
getMasterDB()
Get a connection to the master DB.
Definition: ForeignDBViaLBRepo.php:49
ForeignDBViaLBRepo\assertWritableRepo
assertWritableRepo()
Throw an exception if this repo is read-only by design.
Definition: ForeignDBViaLBRepo.php:75
ForeignDBViaLBRepo\getDBLoadBalancer
getDBLoadBalancer()
Definition: ForeignDBViaLBRepo.php:69
ForeignDBViaLBRepo\__construct
__construct( $info)
Definition: ForeignDBViaLBRepo.php:42
LocalRepo
A repository that stores files in the local filesystem and registers them in the wiki's own database.
Definition: LocalRepo.php:37
Wikimedia\Rdbms\ILoadBalancer
Database cluster connection, tracking, load balancing, and transaction manager interface.
Definition: ILoadBalancer.php:81