Merge "Import: Handle uploads with sha1 starting with 0 properly"
[mediawiki.git] / includes / db / loadbalancer / LBFactorySingle.php
blob5a6cfa753d1423b9253fe66b9e94aaf4f19e8767
1 <?php
2 /**
3 * Simple generator of database connections that always returns the same object.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @ingroup Database
24 /**
25 * An LBFactory class that always returns a single database object.
27 class LBFactorySingle extends LBFactory {
28 /** @var LoadBalancerSingle */
29 private $lb;
31 /**
32 * @param array $conf An associative array with one member:
33 * - connection: The DatabaseBase connection object
35 public function __construct( array $conf ) {
36 parent::__construct( $conf );
38 $conf['readOnlyReason'] = $this->readOnlyReason;
39 $this->lb = new LoadBalancerSingle( $conf );
42 /**
43 * @param bool|string $wiki
44 * @return LoadBalancerSingle
46 public function newMainLB( $wiki = false ) {
47 return $this->lb;
50 /**
51 * @param bool|string $wiki
52 * @return LoadBalancerSingle
54 public function getMainLB( $wiki = false ) {
55 return $this->lb;
58 /**
59 * @param string $cluster External storage cluster, or false for core
60 * @param bool|string $wiki Wiki ID, or false for the current wiki
61 * @return LoadBalancerSingle
63 protected function newExternalLB( $cluster, $wiki = false ) {
64 return $this->lb;
67 /**
68 * @param string $cluster External storage cluster, or false for core
69 * @param bool|string $wiki Wiki ID, or false for the current wiki
70 * @return LoadBalancerSingle
72 public function &getExternalLB( $cluster, $wiki = false ) {
73 return $this->lb;
76 /**
77 * @param string|callable $callback
78 * @param array $params
80 public function forEachLB( $callback, array $params = array() ) {
81 call_user_func_array( $callback, array_merge( array( $this->lb ), $params ) );
85 /**
86 * Helper class for LBFactorySingle.
88 class LoadBalancerSingle extends LoadBalancer {
89 /** @var DatabaseBase */
90 private $db;
92 /**
93 * @param array $params
95 public function __construct( array $params ) {
96 $this->db = $params['connection'];
98 parent::__construct( array(
99 'servers' => array(
100 array(
101 'type' => $this->db->getType(),
102 'host' => $this->db->getServer(),
103 'dbname' => $this->db->getDBname(),
104 'load' => 1,
107 ) );
109 if ( isset( $params['readOnlyReason'] ) ) {
110 $this->db->setLBInfo( 'readOnlyReason', $params['readOnlyReason'] );
116 * @param string $server
117 * @param bool $dbNameOverride
119 * @return DatabaseBase
121 protected function reallyOpenConnection( $server, $dbNameOverride = false ) {
122 return $this->db;