Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F2752653
CentralDBManager.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
CentralDBManager.php
View Options
<?php
namespace
MediaWiki\Extension\AbuseFilter
;
use
Wikimedia\Rdbms\DBError
;
use
Wikimedia\Rdbms\IDatabase
;
use
Wikimedia\Rdbms\LBFactory
;
class
CentralDBManager
{
public
const
SERVICE_NAME
=
'AbuseFilterCentralDBManager'
;
/** @var LBFactory */
private
$loadBalancerFactory
;
/** @var string|false */
private
$dbName
;
/** @var bool */
private
$filterIsCentral
;
/**
* @param LBFactory $loadBalancerFactory
* @param string|false|null $dbName
* @param bool $filterIsCentral
*/
public
function
__construct
(
LBFactory
$loadBalancerFactory
,
$dbName
,
bool
$filterIsCentral
)
{
$this
->
loadBalancerFactory
=
$loadBalancerFactory
;
// Use false to agree with LoadBalancer
$this
->
dbName
=
$dbName
?:
false
;
$this
->
filterIsCentral
=
$filterIsCentral
;
}
/**
* @param int $index DB_PRIMARY/DB_REPLICA
* @return IDatabase
* @throws DBError
* @throws CentralDBNotAvailableException
*/
public
function
getConnection
(
int
$index
):
IDatabase
{
if
(
!
is_string
(
$this
->
dbName
)
)
{
throw
new
CentralDBNotAvailableException
(
'$wgAbuseFilterCentralDB is not configured'
);
}
return
$this
->
loadBalancerFactory
->
getMainLB
(
$this
->
dbName
)
->
getConnection
(
$index
,
[],
$this
->
dbName
);
}
/**
* @return string
* @throws CentralDBNotAvailableException
*/
public
function
getCentralDBName
():
string
{
if
(
!
is_string
(
$this
->
dbName
)
)
{
throw
new
CentralDBNotAvailableException
(
'$wgAbuseFilterCentralDB is not configured'
);
}
return
$this
->
dbName
;
}
/**
* Whether this database is the central one.
* @todo Deprecate the config in favour of just checking whether the current DB is the same
* as $wgAbuseFilterCentralDB.
* @return bool
*/
public
function
filterIsCentral
():
bool
{
return
$this
->
filterIsCentral
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Jul 3, 20:14 (1 d, 17 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
0c/7d/6e18c08cca9403ca29fdb83d89c9
Default Alt Text
CentralDBManager.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment