summaryrefslogtreecommitdiff
path: root/includes/db/LBFactory.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2011-06-22 11:28:20 +0200
committerPierre Schmitz <pierre@archlinux.de>2011-06-22 11:28:20 +0200
commit9db190c7e736ec8d063187d4241b59feaf7dc2d1 (patch)
tree46d1a0dee7febef5c2d57a9f7b972be16a163b3d /includes/db/LBFactory.php
parent78677c7bbdcc9739f6c10c75935898a20e1acd9e (diff)
update to MediaWiki 1.17.0
Diffstat (limited to 'includes/db/LBFactory.php')
-rw-r--r--includes/db/LBFactory.php76
1 files changed, 68 insertions, 8 deletions
diff --git a/includes/db/LBFactory.php b/includes/db/LBFactory.php
index 10c87133..f84a70e5 100644
--- a/includes/db/LBFactory.php
+++ b/includes/db/LBFactory.php
@@ -1,5 +1,7 @@
<?php
/**
+ * Generator of database load balancing objects
+ *
* @file
* @ingroup Database
*/
@@ -12,6 +14,23 @@ abstract class LBFactory {
static $instance;
/**
+ * Disables all access to the load balancer, will cause all database access
+ * to throw a DBAccessError
+ */
+ public static function disableBackend() {
+ global $wgLBFactoryConf;
+ self::$instance = new LBFactory_Fake( $wgLBFactoryConf );
+ }
+
+ /**
+ * Resets the singleton for use if it's been disabled. Does nothing otherwise
+ */
+ public static function enableBackend() {
+ if( self::$instance instanceof LBFactory_Fake )
+ self::$instance = null;
+ }
+
+ /**
* Get an LBFactory instance
*/
static function &singleton() {
@@ -36,6 +55,14 @@ abstract class LBFactory {
}
/**
+ * Set the instance to be the given object
+ */
+ static function setInstance( $instance ) {
+ self::destroyInstance();
+ self::$instance = $instance;
+ }
+
+ /**
* Construct a factory based on a configuration array (typically from $wgLBFactoryConf)
*/
abstract function __construct( $conf );
@@ -44,7 +71,7 @@ abstract class LBFactory {
* Create a new load balancer object. The resulting object will be untracked,
* not chronology-protected, and the caller is responsible for cleaning it up.
*
- * @param string $wiki Wiki ID, or false for the current wiki
+ * @param $wiki String: wiki ID, or false for the current wiki
* @return LoadBalancer
*/
abstract function newMainLB( $wiki = false );
@@ -52,7 +79,7 @@ abstract class LBFactory {
/**
* Get a cached (tracked) load balancer object.
*
- * @param string $wiki Wiki ID, or false for the current wiki
+ * @param $wiki String: wiki ID, or false for the current wiki
* @return LoadBalancer
*/
abstract function getMainLB( $wiki = false );
@@ -62,16 +89,16 @@ abstract class LBFactory {
* untracked, not chronology-protected, and the caller is responsible for
* cleaning it up.
*
- * @param string $cluster External storage cluster, or false for core
- * @param string $wiki Wiki ID, or false for the current wiki
+ * @param $cluster String: external storage cluster, or false for core
+ * @param $wiki String: wiki ID, or false for the current wiki
*/
abstract function newExternalLB( $cluster, $wiki = false );
/*
* Get a cached (tracked) load balancer for external storage
*
- * @param string $cluster External storage cluster, or false for core
- * @param string $wiki Wiki ID, or false for the current wiki
+ * @param $cluster String: external storage cluster, or false for core
+ * @param $wiki String: wiki ID, or false for the current wiki
*/
abstract function &getExternalLB( $cluster, $wiki = false );
@@ -198,6 +225,39 @@ class LBFactory_Simple extends LBFactory {
}
/**
+ * LBFactory class that throws an error on any attempt to use it.
+ * This will typically be done via wfGetDB().
+ * Call LBFactory::disableBackend() to start using this, and
+ * LBFactory::enableBackend() to return to normal behavior
+ */
+class LBFactory_Fake extends LBFactory {
+ function __construct( $conf ) {}
+
+ function newMainLB( $wiki = false) {
+ throw new DBAccessError;
+ }
+ function getMainLB( $wiki = false ) {
+ throw new DBAccessError;
+ }
+ function newExternalLB( $cluster, $wiki = false ) {
+ throw new DBAccessError;
+ }
+ function &getExternalLB( $cluster, $wiki = false ) {
+ throw new DBAccessError;
+ }
+ function forEachLB( $callback, $params = array() ) {}
+}
+
+/**
+ * Exception class for attempted DB access
+ */
+class DBAccessError extends MWException {
+ function __construct() {
+ parent::__construct( "Mediawiki tried to access the database via wfGetDB(). This is not allowed." );
+ }
+}
+
+/**
* Class for ensuring a consistent ordering of events as seen by the user, despite replication.
* Kind of like Hawking's [[Chronology Protection Agency]].
*/
@@ -208,7 +268,7 @@ class ChronologyProtector {
/**
* Initialise a LoadBalancer to give it appropriate chronology protection.
*
- * @param LoadBalancer $lb
+ * @param $lb LoadBalancer
*/
function initLB( $lb ) {
if ( $this->startupPos === null ) {
@@ -233,7 +293,7 @@ class ChronologyProtector {
* Notify the ChronologyProtector that the LoadBalancer is about to shut
* down. Saves replication positions.
*
- * @param LoadBalancer $lb
+ * @param $lb LoadBalancer
*/
function shutdownLB( $lb ) {
// Don't start a session, don't bother with non-replicated setups