MediaWiki REL1_35
ForeignDBRepo.php
Go to the documentation of this file.
1<?php
27
33class ForeignDBRepo extends LocalRepo {
35 protected $dbType;
36
38 protected $dbServer;
39
41 protected $dbUser;
42
44 protected $dbPassword;
45
47 protected $dbName;
48
50 protected $dbFlags;
51
53 protected $tablePrefix;
54
56 protected $hasSharedCache;
57
59 protected $dbConn;
60
62 protected $fileFactory = [ ForeignDBFile::class, 'newFromTitle' ];
64 protected $fileFromRowFactory = [ ForeignDBFile::class, 'newFromRow' ];
65
67 private $dbDomain;
68
72 public function __construct( $info ) {
73 parent::__construct( $info );
74 '@phan-var array $info';
75 $this->dbType = $info['dbType'];
76 $this->dbServer = $info['dbServer'];
77 $this->dbUser = $info['dbUser'];
78 $this->dbPassword = $info['dbPassword'];
79 $this->dbName = $info['dbName'];
80 $this->dbFlags = $info['dbFlags'];
81 $this->tablePrefix = $info['tablePrefix'];
82 $this->hasSharedCache = $info['hasSharedCache'];
83
84 $dbDomain = new DatabaseDomain( $this->dbName, null, $this->tablePrefix );
85 $this->dbDomain = $dbDomain->getId();
86 }
87
88 public function getMasterDB() {
89 if ( !isset( $this->dbConn ) ) {
90 $func = $this->getDBFactory();
91 $this->dbConn = $func( DB_MASTER );
92 }
93
94 return $this->dbConn;
95 }
96
97 public function getReplicaDB() {
98 return $this->getMasterDB();
99 }
100
104 protected function getDBFactory() {
106 $params = [
107 'host' => $this->dbServer,
108 'user' => $this->dbUser,
109 'password' => $this->dbPassword,
110 'dbname' => $this->dbName,
111 'flags' => $this->dbFlags,
112 'tablePrefix' => $this->tablePrefix
113 ];
114
115 return function ( $index ) use ( $type, $params ) {
116 return Database::factory( $type, $params );
117 };
118 }
119
123 private function hasSharedCache() {
125 }
126
127 public function getSharedCacheKey( ...$args ) {
128 if ( $this->hasSharedCache() ) {
129 return $this->wanCache->makeGlobalKey( $this->dbDomain, ...$args );
130 } else {
131 return false;
132 }
133 }
134
135 protected function assertWritableRepo() {
136 throw new MWException( static::class . ': write operations are not supported.' );
137 }
138
145 public function getInfo() {
146 return FileRepo::getInfo();
147 }
148}
getInfo()
Return information about the repository.
A foreign repository with an accessible MediaWiki database.
getInfo()
Return information about the repository.
callable $fileFactory
IDatabase $dbConn
assertWritableRepo()
Throw an exception if this repo is read-only by design.
getReplicaDB()
Get a connection to the replica DB.
callable $fileFromRowFactory
getMasterDB()
Get a connection to the master DB.
__construct( $info)
getSharedCacheKey(... $args)
Get a key on the primary cache for this repository.
A repository that stores files in the local filesystem and registers them in the wiki's own database.
Definition LocalRepo.php:37
MediaWiki exception.
Class to handle database/schema/prefix specifications for IDatabase.
Relational database abstraction object.
Definition Database.php:50
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:38
if( $line===false) $args
Definition mcc.php:124
const DB_MASTER
Definition defines.php:29