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 getPrimaryDB() {
50  return $this->getDBLoadBalancer()->getConnectionRef( DB_PRIMARY, [], $this->dbDomain );
51  }
52 
53  public function getMasterDB() {
54  wfDeprecated( __METHOD__, '1.37' );
55  return $this->getPrimaryDB();
56  }
57 
58  public function getReplicaDB() {
59  return $this->getDBLoadBalancer()->getConnectionRef( DB_REPLICA, [], $this->dbDomain );
60  }
61 
65  protected function getDBFactory() {
66  return function ( $index ) {
67  return $this->getDBLoadBalancer()->getConnectionRef( $index, [], $this->dbDomain );
68  };
69  }
70 
74  protected function getDBLoadBalancer() {
75  $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
76 
77  return $lbFactory->getMainLB( $this->dbDomain );
78  }
79 
80  protected function assertWritableRepo() {
81  throw new MWException( static::class . ': write operations are not supported.' );
82  }
83 
84  public function getInfo() {
85  return FileRepo::getInfo();
86  }
87 }
ForeignDBViaLBRepo\getDBFactory
getDBFactory()
Definition: ForeignDBViaLBRepo.php:65
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:193
FileRepo\getInfo
getInfo()
Return information about the repository.
Definition: FileRepo.php:1983
ForeignDBViaLBRepo\$fileFromRowFactory
array $fileFromRowFactory
Definition: ForeignDBViaLBRepo.php:37
ForeignDBViaLBRepo\getInfo
getInfo()
Return information about the repository.
Definition: ForeignDBViaLBRepo.php:84
MWException
MediaWiki exception.
Definition: MWException.php:29
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
Definition: GlobalFunctions.php:997
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
ForeignDBViaLBRepo\getReplicaDB
getReplicaDB()
Get a connection to the replica DB.
Definition: ForeignDBViaLBRepo.php:58
DB_PRIMARY
const DB_PRIMARY
Definition: defines.php:27
ForeignDBViaLBRepo\getMasterDB
getMasterDB()
Get a connection to the primary DB.
Definition: ForeignDBViaLBRepo.php:53
ForeignDBViaLBRepo\assertWritableRepo
assertWritableRepo()
Throw an exception if this repo is read-only by design.
Definition: ForeignDBViaLBRepo.php:80
ForeignDBViaLBRepo\getDBLoadBalancer
getDBLoadBalancer()
Definition: ForeignDBViaLBRepo.php:74
ForeignDBViaLBRepo\__construct
__construct( $info)
Definition: ForeignDBViaLBRepo.php:42
ForeignDBViaLBRepo\getPrimaryDB
getPrimaryDB()
Get a connection to the primary DB.
Definition: ForeignDBViaLBRepo.php:49
LocalRepo
A repository that stores files in the local filesystem and registers them in the wiki's own database.
Definition: LocalRepo.php:41
Wikimedia\Rdbms\ILoadBalancer
Database cluster connection, tracking, load balancing, and transaction manager interface.
Definition: ILoadBalancer.php:81