MediaWiki  master
ForeignDBRepo.php
Go to the documentation of this file.
1 <?php
26 
32 class ForeignDBRepo extends LocalRepo {
34  protected $dbType;
35 
37  protected $dbServer;
38 
40  protected $dbUser;
41 
43  protected $dbPassword;
44 
46  protected $dbName;
47 
49  protected $dbFlags;
50 
52  protected $tablePrefix;
53 
55  protected $hasSharedCache;
56 
58  protected $dbConn;
59 
61  protected $fileFactory = [ ForeignDBFile::class, 'newFromTitle' ];
63  protected $fileFromRowFactory = [ ForeignDBFile::class, 'newFromRow' ];
64 
68  function __construct( $info ) {
69  parent::__construct( $info );
70  '@phan-var array $info';
71  $this->dbType = $info['dbType'];
72  $this->dbServer = $info['dbServer'];
73  $this->dbUser = $info['dbUser'];
74  $this->dbPassword = $info['dbPassword'];
75  $this->dbName = $info['dbName'];
76  $this->dbFlags = $info['dbFlags'];
77  $this->tablePrefix = $info['tablePrefix'];
78  $this->hasSharedCache = $info['hasSharedCache'];
79  }
80 
84  function getMasterDB() {
85  if ( !isset( $this->dbConn ) ) {
86  $func = $this->getDBFactory();
87  $this->dbConn = $func( DB_MASTER );
88  }
89 
90  return $this->dbConn;
91  }
92 
96  function getReplicaDB() {
97  return $this->getMasterDB();
98  }
99 
103  protected function getDBFactory() {
105  $params = [
106  'host' => $this->dbServer,
107  'user' => $this->dbUser,
108  'password' => $this->dbPassword,
109  'dbname' => $this->dbName,
110  'flags' => $this->dbFlags,
111  'tablePrefix' => $this->tablePrefix
112  ];
113 
114  return function ( $index ) use ( $type, $params ) {
115  return Database::factory( $type, $params );
116  };
117  }
118 
122  function hasSharedCache() {
123  return $this->hasSharedCache;
124  }
125 
133  function getSharedCacheKey( ...$args ) {
134  if ( $this->hasSharedCache() ) {
135  return wfForeignMemcKey( $this->dbName, $this->tablePrefix, ...$args );
136  } else {
137  return false;
138  }
139  }
140 
141  protected function assertWritableRepo() {
142  throw new MWException( static::class . ': write operations are not supported.' );
143  }
144 
151  function getInfo() {
152  return FileRepo::getInfo();
153  }
154 }
A foreign repository with an accessible MediaWiki database.
string $tablePrefix
wfForeignMemcKey( $db, $prefix,... $args)
Make a cache key for a foreign DB.
getInfo()
Return information about the repository.
A repository that stores files in the local filesystem and registers them in the wiki&#39;s own database...
Definition: LocalRepo.php:37
const DB_MASTER
Definition: defines.php:26
getSharedCacheKey(... $args)
Get a key on the primary cache for this repository.
if( $line===false) $args
Definition: mcc.php:124
IDatabase $dbConn
getInfo()
Return information about the repository.
Definition: FileRepo.php:1938
__construct( $info)
string $dbPassword
callable $fileFactory
callable $fileFromRowFactory