MediaWiki  master
ForeignDBViaLBRepo.php
Go to the documentation of this file.
1 <?php
27 
35  protected $wiki;
36 
38  protected $fileFactory = [ ForeignDBFile::class, 'newFromTitle' ];
39 
41  protected $fileFromRowFactory = [ ForeignDBFile::class, 'newFromRow' ];
42 
44  protected $hasSharedCache;
45 
49  function __construct( $info ) {
50  parent::__construct( $info );
51  '@phan-var array $info';
52  $this->wiki = $info['wiki'];
53  $this->hasSharedCache = $info['hasSharedCache'];
54  }
55 
59  function getMasterDB() {
60  return $this->getDBLoadBalancer()->getConnectionRef( DB_MASTER, [], $this->wiki );
61  }
62 
66  function getReplicaDB() {
67  return $this->getDBLoadBalancer()->getConnectionRef( DB_REPLICA, [], $this->wiki );
68  }
69 
73  protected function getDBFactory() {
74  return function ( $index ) {
75  return $this->getDBLoadBalancer()->getConnectionRef( $index, [], $this->wiki );
76  };
77  }
78 
82  protected function getDBLoadBalancer() {
83  $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
84 
85  return $lbFactory->getMainLB( $this->wiki );
86  }
87 
88  function hasSharedCache() {
89  return $this->hasSharedCache;
90  }
91 
99  function getSharedCacheKey( ...$args ) {
100  if ( $this->hasSharedCache() ) {
101  array_unshift( $args, $this->wiki );
102 
103  return implode( ':', $args );
104  } else {
105  return false;
106  }
107  }
108 
109  protected function assertWritableRepo() {
110  throw new MWException( static::class . ': write operations are not supported.' );
111  }
112 
113  public function getInfo() {
114  return FileRepo::getInfo();
115  }
116 }
ForeignDBViaLBRepo\getDBFactory
getDBFactory()
Definition: ForeignDBViaLBRepo.php:73
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:130
ForeignDBViaLBRepo\getSharedCacheKey
getSharedCacheKey(... $args)
Get a key on the primary cache for this repository.
Definition: ForeignDBViaLBRepo.php:99
FileRepo\getInfo
getInfo()
Return information about the repository.
Definition: FileRepo.php:1941
ForeignDBViaLBRepo\$fileFromRowFactory
array $fileFromRowFactory
Definition: ForeignDBViaLBRepo.php:41
ForeignDBViaLBRepo\$wiki
string $wiki
Definition: ForeignDBViaLBRepo.php:35
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
ForeignDBViaLBRepo\getInfo
getInfo()
Return information about the repository.
Definition: ForeignDBViaLBRepo.php:113
MWException
MediaWiki exception.
Definition: MWException.php:26
ForeignDBViaLBRepo
A foreign repository with a MediaWiki database accessible via the configured LBFactory.
Definition: ForeignDBViaLBRepo.php:33
$args
if( $line===false) $args
Definition: mcc.php:124
ForeignDBViaLBRepo\$fileFactory
array $fileFactory
Definition: ForeignDBViaLBRepo.php:38
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
DB_MASTER
const DB_MASTER
Definition: defines.php:26
ForeignDBViaLBRepo\getReplicaDB
getReplicaDB()
Definition: ForeignDBViaLBRepo.php:66
ForeignDBViaLBRepo\$hasSharedCache
bool $hasSharedCache
Definition: ForeignDBViaLBRepo.php:44
ForeignDBViaLBRepo\getMasterDB
getMasterDB()
Definition: ForeignDBViaLBRepo.php:59
ForeignDBViaLBRepo\assertWritableRepo
assertWritableRepo()
Throw an exception if this repo is read-only by design.
Definition: ForeignDBViaLBRepo.php:109
ForeignDBViaLBRepo\hasSharedCache
hasSharedCache()
Definition: ForeignDBViaLBRepo.php:88
ForeignDBViaLBRepo\getDBLoadBalancer
getDBLoadBalancer()
Definition: ForeignDBViaLBRepo.php:82
ForeignDBViaLBRepo\__construct
__construct( $info)
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:37
Wikimedia\Rdbms\ILoadBalancer
Database cluster connection, tracking, load balancing, and transaction manager interface.
Definition: ILoadBalancer.php:81