MediaWiki  master
ForeignDBViaLBRepo.php
Go to the documentation of this file.
1 <?php
26 
34  protected $wiki;
35 
37  protected $fileFactory = [ ForeignDBFile::class, 'newFromTitle' ];
38 
40  protected $fileFromRowFactory = [ ForeignDBFile::class, 'newFromRow' ];
41 
43  protected $hasSharedCache;
44 
48  public function __construct( $info ) {
49  parent::__construct( $info );
50  '@phan-var array $info';
51  $this->wiki = $info['wiki'];
52  $this->hasSharedCache = $info['hasSharedCache'];
53  }
54 
55  public function getMasterDB() {
56  return $this->getDBLoadBalancer()->getConnectionRef( DB_MASTER, [], $this->wiki );
57  }
58 
59  public function getReplicaDB() {
60  return $this->getDBLoadBalancer()->getConnectionRef( DB_REPLICA, [], $this->wiki );
61  }
62 
66  protected function getDBFactory() {
67  return function ( $index ) {
68  return $this->getDBLoadBalancer()->getConnectionRef( $index, [], $this->wiki );
69  };
70  }
71 
75  protected function getDBLoadBalancer() {
76  $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
77 
78  return $lbFactory->getMainLB( $this->wiki );
79  }
80 
81  private function hasSharedCache() {
82  return $this->hasSharedCache;
83  }
84 
85  public function getSharedCacheKey( ...$args ) {
86  if ( $this->hasSharedCache() ) {
87  return $this->wanCache->makeGlobalKey( $this->wiki, ...$args );
88  } else {
89  return false;
90  }
91  }
92 
93  protected function assertWritableRepo() {
94  throw new MWException( static::class . ': write operations are not supported.' );
95  }
96 
97  public function getInfo() {
98  return FileRepo::getInfo();
99  }
100 }
ForeignDBViaLBRepo\getDBFactory
getDBFactory()
Definition: ForeignDBViaLBRepo.php:66
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:158
ForeignDBViaLBRepo\getSharedCacheKey
getSharedCacheKey(... $args)
Get a key on the primary cache for this repository.
Definition: ForeignDBViaLBRepo.php:85
FileRepo\getInfo
getInfo()
Return information about the repository.
Definition: FileRepo.php:1946
ForeignDBViaLBRepo\$fileFromRowFactory
array $fileFromRowFactory
Definition: ForeignDBViaLBRepo.php:40
ForeignDBViaLBRepo\$wiki
string $wiki
Definition: ForeignDBViaLBRepo.php:34
ForeignDBViaLBRepo\getInfo
getInfo()
Return information about the repository.
Definition: ForeignDBViaLBRepo.php:97
MWException
MediaWiki exception.
Definition: MWException.php:29
ForeignDBViaLBRepo
A foreign repository with a MediaWiki database accessible via the configured LBFactory.
Definition: ForeignDBViaLBRepo.php:32
$args
if( $line===false) $args
Definition: mcc.php:124
ForeignDBViaLBRepo\$fileFactory
array $fileFactory
Definition: ForeignDBViaLBRepo.php:37
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:59
ForeignDBViaLBRepo\$hasSharedCache
bool $hasSharedCache
Definition: ForeignDBViaLBRepo.php:43
ForeignDBViaLBRepo\getMasterDB
getMasterDB()
Get a connection to the master DB.
Definition: ForeignDBViaLBRepo.php:55
ForeignDBViaLBRepo\assertWritableRepo
assertWritableRepo()
Throw an exception if this repo is read-only by design.
Definition: ForeignDBViaLBRepo.php:93
ForeignDBViaLBRepo\hasSharedCache
hasSharedCache()
Definition: ForeignDBViaLBRepo.php:81
ForeignDBViaLBRepo\getDBLoadBalancer
getDBLoadBalancer()
Definition: ForeignDBViaLBRepo.php:75
ForeignDBViaLBRepo\__construct
__construct( $info)
Definition: ForeignDBViaLBRepo.php:48
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