From: Aaron Schulz Date: Fri, 24 Apr 2015 17:00:22 +0000 (-0700) Subject: Moved DBConnRef to a separate file X-Git-Tag: 1.31.0-rc.0~11598^2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/categories/modifier.php?a=commitdiff_plain;h=fb10df98df5cad78312e270f2d59733c5d2a3ce5;p=lhc%2Fweb%2Fwiklou.git Moved DBConnRef to a separate file Change-Id: I9c8570aefb8927a3d69b7fd446165f6e8661e84d --- diff --git a/autoload.php b/autoload.php index 754b1bb5ef..71bc7b2e9f 100644 --- a/autoload.php +++ b/autoload.php @@ -278,7 +278,7 @@ $wgAutoloadLocalClasses = array( 'CurlHttpRequest' => __DIR__ . '/includes/HttpFunctions.php', 'DBAccessBase' => __DIR__ . '/includes/dao/DBAccessBase.php', 'DBAccessError' => __DIR__ . '/includes/db/LBFactory.php', - 'DBConnRef' => __DIR__ . '/includes/db/LoadBalancer.php', + 'DBConnRef' => __DIR__ . '/includes/db/DBConnRef.php', 'DBConnectionError' => __DIR__ . '/includes/db/DatabaseError.php', 'DBError' => __DIR__ . '/includes/db/DatabaseError.php', 'DBExpectedError' => __DIR__ . '/includes/db/DatabaseError.php', diff --git a/includes/db/DBConnRef.php b/includes/db/DBConnRef.php new file mode 100644 index 0000000000..7045494abd --- /dev/null +++ b/includes/db/DBConnRef.php @@ -0,0 +1,46 @@ +lb = $lb; + if ( $conn instanceof DatabaseBase ) { + $this->conn = $conn; + } else { + $this->params = $conn; + } + } + + public function __call( $name, $arguments ) { + if ( $this->conn === null ) { + list( $db, $groups, $wiki ) = $this->params; + $this->conn = $this->lb->getConnection( $db, $groups, $wiki ); + } + + return call_user_func_array( array( $this->conn, $name ), $arguments ); + } + + public function __destruct() { + if ( $this->conn !== null ) { + $this->lb->reuseConnection( $this->conn ); + } + } +} diff --git a/includes/db/LoadBalancer.php b/includes/db/LoadBalancer.php index 624f46bc3b..e1ecf84e10 100644 --- a/includes/db/LoadBalancer.php +++ b/includes/db/LoadBalancer.php @@ -1272,49 +1272,3 @@ class LoadBalancer { $this->mProcCache->clear( 'slave_lag' ); } } - -/** - * Helper class to handle automatically marking connections as reusable (via RAII pattern) - * as well handling deferring the actual network connection until the handle is used - * - * @ingroup Database - * @since 1.22 - */ -class DBConnRef implements IDatabase { - /** @var LoadBalancer */ - private $lb; - - /** @var DatabaseBase|null */ - private $conn; - - /** @var array|null */ - private $params; - - /** - * @param LoadBalancer $lb - * @param DatabaseBase|array $conn Connection or (server index, group, wiki ID) array - */ - public function __construct( LoadBalancer $lb, $conn ) { - $this->lb = $lb; - if ( $conn instanceof DatabaseBase ) { - $this->conn = $conn; - } else { - $this->params = $conn; - } - } - - public function __call( $name, $arguments ) { - if ( $this->conn === null ) { - list( $db, $groups, $wiki ) = $this->params; - $this->conn = $this->lb->getConnection( $db, $groups, $wiki ); - } - - return call_user_func_array( array( $this->conn, $name ), $arguments ); - } - - public function __destruct() { - if ( $this->conn !== null ) { - $this->lb->reuseConnection( $this->conn ); - } - } -}