MediaWiki  master
ForeignDBRepo.php
Go to the documentation of this file.
1 <?php
27 
33 class 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() {
124  return $this->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 }
ForeignDBRepo\$dbUser
string $dbUser
Definition: ForeignDBRepo.php:41
Wikimedia\Rdbms\Database
Relational database abstraction object.
Definition: Database.php:49
ForeignDBRepo\getDBFactory
getDBFactory()
Definition: ForeignDBRepo.php:104
ForeignDBRepo\getInfo
getInfo()
Return information about the repository.
Definition: ForeignDBRepo.php:145
ForeignDBRepo\$hasSharedCache
bool $hasSharedCache
Definition: ForeignDBRepo.php:56
ForeignDBRepo\$dbName
string $dbName
Definition: ForeignDBRepo.php:47
FileRepo\getInfo
getInfo()
Return information about the repository.
Definition: FileRepo.php:1943
ForeignDBRepo\getReplicaDB
getReplicaDB()
Get a connection to the replica DB.
Definition: ForeignDBRepo.php:97
ForeignDBRepo\assertWritableRepo
assertWritableRepo()
Throw an exception if this repo is read-only by design.
Definition: ForeignDBRepo.php:135
ForeignDBRepo\$fileFactory
callable $fileFactory
Definition: ForeignDBRepo.php:62
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
ForeignDBRepo\$dbServer
string $dbServer
Definition: ForeignDBRepo.php:38
ForeignDBRepo\$dbConn
IDatabase $dbConn
Definition: ForeignDBRepo.php:59
MWException
MediaWiki exception.
Definition: MWException.php:26
ForeignDBRepo\$dbPassword
string $dbPassword
Definition: ForeignDBRepo.php:44
$args
if( $line===false) $args
Definition: mcc.php:124
DB_MASTER
const DB_MASTER
Definition: defines.php:26
ForeignDBRepo\$tablePrefix
string $tablePrefix
Definition: ForeignDBRepo.php:53
ForeignDBRepo\hasSharedCache
hasSharedCache()
Definition: ForeignDBRepo.php:123
ForeignDBRepo
A foreign repository with an accessible MediaWiki database.
Definition: ForeignDBRepo.php:33
ForeignDBRepo\getSharedCacheKey
getSharedCacheKey(... $args)
Get a key on the primary cache for this repository.
Definition: ForeignDBRepo.php:127
ForeignDBRepo\getMasterDB
getMasterDB()
Get a connection to the master DB.
Definition: ForeignDBRepo.php:88
ForeignDBRepo\$dbType
string $dbType
Definition: ForeignDBRepo.php:35
ForeignDBRepo\$dbFlags
string $dbFlags
Definition: ForeignDBRepo.php:50
ForeignDBRepo\__construct
__construct( $info)
Definition: ForeignDBRepo.php:72
Wikimedia\Rdbms\DatabaseDomain
Class to handle database/schema/prefix specifications for IDatabase.
Definition: DatabaseDomain.php:40
ForeignDBRepo\$dbDomain
string $dbDomain
Definition: ForeignDBRepo.php:67
ForeignDBRepo\$fileFromRowFactory
callable $fileFromRowFactory
Definition: ForeignDBRepo.php:64
LocalRepo
A repository that stores files in the local filesystem and registers them in the wiki's own database.
Definition: LocalRepo.php:37
$type
$type
Definition: testCompression.php:52