MediaWiki  1.34.0
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  $this->wiki = $info['wiki'];
52  $this->hasSharedCache = $info['hasSharedCache'];
53  }
54 
58  function getMasterDB() {
59  return $this->getDBLoadBalancer()->getConnectionRef( DB_MASTER, [], $this->wiki );
60  }
61 
65  function getReplicaDB() {
66  return $this->getDBLoadBalancer()->getConnectionRef( DB_REPLICA, [], $this->wiki );
67  }
68 
72  protected function getDBFactory() {
73  return function ( $index ) {
74  return $this->getDBLoadBalancer()->getConnectionRef( $index, [], $this->wiki );
75  };
76  }
77 
81  protected function getDBLoadBalancer() {
82  $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
83 
84  return $lbFactory->getMainLB( $this->wiki );
85  }
86 
87  function hasSharedCache() {
88  return $this->hasSharedCache;
89  }
90 
97  function getSharedCacheKey( /*...*/ ) {
98  if ( $this->hasSharedCache() ) {
99  $args = func_get_args();
100  array_unshift( $args, $this->wiki );
101 
102  return implode( ':', $args );
103  } else {
104  return false;
105  }
106  }
107 
108  protected function assertWritableRepo() {
109  throw new MWException( static::class . ': write operations are not supported.' );
110  }
111 
112  public function getInfo() {
113  return FileRepo::getInfo();
114  }
115 }
ForeignDBViaLBRepo\getDBFactory
getDBFactory()
Definition: ForeignDBViaLBRepo.php:72
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:117
FileRepo\getInfo
getInfo()
Return information about the repository.
Definition: FileRepo.php:1919
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:112
MWException
MediaWiki exception.
Definition: MWException.php:26
ForeignDBViaLBRepo
A foreign repository with a MediaWiki database accessible via the configured LBFactory.
Definition: ForeignDBViaLBRepo.php:33
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:65
ForeignDBViaLBRepo\$hasSharedCache
bool $hasSharedCache
Definition: ForeignDBViaLBRepo.php:44
ForeignDBViaLBRepo\getMasterDB
getMasterDB()
Definition: ForeignDBViaLBRepo.php:58
ForeignDBViaLBRepo\assertWritableRepo
assertWritableRepo()
Throw an exception if this repo is read-only by design.
Definition: ForeignDBViaLBRepo.php:108
ForeignDBViaLBRepo\getSharedCacheKey
getSharedCacheKey()
Get a key on the primary cache for this repository.
Definition: ForeignDBViaLBRepo.php:97
ForeignDBViaLBRepo\hasSharedCache
hasSharedCache()
Definition: ForeignDBViaLBRepo.php:87
$args
if( $line===false) $args
Definition: cdb.php:64
ForeignDBViaLBRepo\getDBLoadBalancer
getDBLoadBalancer()
Definition: ForeignDBViaLBRepo.php:81
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