jenkins-bot has submitted this change and it was merged.
Change subject: Cleaned up DatabaseBase constructor to use an array
......................................................................
Cleaned up DatabaseBase constructor to use an array
Change-Id: I094185585dc844ca4d2d8b629107b2ab8f9bef39
---
M includes/db/Database.php
M includes/db/DatabaseOracle.php
M includes/db/DatabaseSqlite.php
M tests/phpunit/includes/db/DatabaseMysqlBaseTest.php
4 files changed, 76 insertions(+), 44 deletions(-)
Approvals:
Chad: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/db/Database.php b/includes/db/Database.php
index cd907e9..4a84578 100644
--- a/includes/db/Database.php
+++ b/includes/db/Database.php
@@ -681,29 +681,37 @@
* connection object, by specifying no parameters to __construct(). This
* feature is deprecated and should be removed.
*
- * FIXME: The long list of formal parameters here is not really
appropriate
- * for MySQL, and not at all appropriate for any other DBMS. It should
be
- * replaced by named parameters as in DatabaseBase::factory().
- *
* DatabaseBase subclasses should not be constructed directly in
external
* code. DatabaseBase::factory() should be used instead.
*
- * @param string $server database server host
- * @param string $user database user name
- * @param string $password database user password
- * @param string $dbName database name
- * @param $flags
- * @param string $tablePrefix database table prefixes. By default use
the prefix gave in LocalSettings.php
- * @param bool $foreign disable some operations specific to local
databases
+ * @param array Parameters passed from DatabaseBase::factory()
*/
- function __construct( $server = false, $user = false, $password =
false, $dbName = false,
- $flags = 0, $tablePrefix = 'get from global', $foreign = false
- ) {
+ function __construct( $params = null ) {
global $wgDBprefix, $wgCommandLineMode, $wgDebugDBTransactions;
$this->mTrxAtomicLevels = new SplStack;
- $this->mFlags = $flags;
+ if ( is_array( $params ) ) { // MW 1.22
+ $server = $params['host'];
+ $user = $params['user'];
+ $password = $params['password'];
+ $dbName = $params['dbname'];
+ $flags = $params['flags'];
+ $tablePrefix = $params['tablePrefix'];
+ $foreign = $params['foreign'];
+ } else { // legacy calling pattern
+ wfDeprecated( __METHOD__ . " method called without
parameter array.", "1.22" );
+ $args = func_get_args();
+ $server = isset( $args[0] ) ? $args[0] : false;
+ $user = isset( $args[1] ) ? $args[1] : false;
+ $password = isset( $args[2] ) ? $args[2] : false;
+ $dbName = isset( $args[3] ) ? $args[3] : false;
+ $flags = isset( $args[4] ) ? $args[4] : 0;
+ $tablePrefix = isset( $args[5] ) ? $args[5] : 'get from
global';
+ $foreign = isset( $args[6] ) ? $args[6] : false;
+ }
+
+ $this->mFlags = $flags;
if ( $this->mFlags & DBO_DEFAULT ) {
if ( $wgCommandLineMode ) {
$this->mFlags &= ~DBO_TRX;
@@ -800,15 +808,16 @@
$class = 'Database' . ucfirst( $driver );
if ( class_exists( $class ) && is_subclass_of( $class,
'DatabaseBase' ) ) {
- return new $class(
- isset( $p['host'] ) ? $p['host'] : false,
- isset( $p['user'] ) ? $p['user'] : false,
- isset( $p['password'] ) ? $p['password'] :
false,
- isset( $p['dbname'] ) ? $p['dbname'] : false,
- isset( $p['flags'] ) ? $p['flags'] : 0,
- isset( $p['tablePrefix'] ) ? $p['tablePrefix']
: 'get from global',
- isset( $p['foreign'] ) ? $p['foreign'] : false
+ $params = array(
+ 'host' => isset( $p['host'] ) ? $p['host'] :
false,
+ 'user' => isset( $p['user'] ) ? $p['user'] :
false,
+ 'password' => isset( $p['password'] ) ?
$p['password'] : false,
+ 'dbname' => isset( $p['dbname'] ) ?
$p['dbname'] : false,
+ 'flags' => isset( $p['flags'] ) ? $p['flags'] :
0,
+ 'tablePrefix' => isset( $p['tablePrefix'] ) ?
$p['tablePrefix'] : 'get from global',
+ 'foreign' => isset( $p['foreign'] ) ?
$p['foreign'] : false
);
+ return new $class( $params );
} else {
return null;
}
diff --git a/includes/db/DatabaseOracle.php b/includes/db/DatabaseOracle.php
index fbaa4da..97070fb 100644
--- a/includes/db/DatabaseOracle.php
+++ b/includes/db/DatabaseOracle.php
@@ -196,12 +196,27 @@
var $mFieldInfoCache = array();
- function __construct( $server = false, $user = false, $password =
false, $dbName = false,
- $flags = 0, $tablePrefix = 'get from global' )
- {
+ function __construct( $p = null ) {
global $wgDBprefix;
- $tablePrefix = $tablePrefix == 'get from global' ? strtoupper(
$wgDBprefix ) : strtoupper( $tablePrefix );
- parent::__construct( $server, $user, $password, $dbName,
$flags, $tablePrefix );
+
+ if ( !is_array( $p ) ) { // legacy calling pattern
+ wfDeprecated( __METHOD__ . " method called without
parameter array.", "1.22" );
+ $args = func_get_args();
+ $p = array(
+ 'host' => isset( $args[0] ) ? $args[0] : false,
+ 'user' => isset( $args[1] ) ? $args[1] : false,
+ 'password' => isset( $args[2] ) ? $args[2] :
false,
+ 'dbname' => isset( $args[3] ) ? $args[3] :
false,
+ 'flags' => isset( $args[4] ) ? $args[4] : 0,
+ 'tablePrefix' => isset( $args[5] ) ? $args[5] :
'get from global',
+ 'foreign' => isset( $args[6] ) ? $args[6] :
false
+ );
+ }
+ if ( $p['tablePrefix'] == 'get from global' ) {
+ $p['tablePrefix'] = $wgDBprefix;
+ }
+ $p['tablePrefix'] = strtoupper( $p['tablePrefix'] );
+ parent::__construct( $p );
wfRunHooks( 'DatabaseOraclePostInit', array( $this ) );
}
diff --git a/includes/db/DatabaseSqlite.php b/includes/db/DatabaseSqlite.php
index 06dfd84..79a3b1e 100644
--- a/includes/db/DatabaseSqlite.php
+++ b/includes/db/DatabaseSqlite.php
@@ -39,23 +39,30 @@
*/
protected $mConn;
- /**
- * Constructor.
- * Parameters $server, $user and $password are not used.
- * @param $server string
- * @param $user string
- * @param $password string
- * @param $dbName string
- * @param $flags int
- */
- function __construct( $server = false, $user = false, $password =
false, $dbName = false, $flags = 0 ) {
- $this->mName = $dbName;
- parent::__construct( $server, $user, $password, $dbName, $flags
);
+ function __construct( $p = null ) {
+ global $wgSharedDB;
+
+ if ( !is_array( $p ) ) { // legacy calling pattern
+ wfDeprecated( __METHOD__ . " method called without
parameter array.", "1.22" );
+ $args = func_get_args();
+ $p = array(
+ 'host' => isset( $args[0] ) ? $args[0] : false,
+ 'user' => isset( $args[1] ) ? $args[1] : false,
+ 'password' => isset( $args[2] ) ? $args[2] :
false,
+ 'dbname' => isset( $args[3] ) ? $args[3] :
false,
+ 'flags' => isset( $args[4] ) ? $args[4] : 0,
+ 'tablePrefix' => isset( $args[5] ) ? $args[5] :
'get from global',
+ 'foreign' => isset( $args[6] ) ? $args[6] :
false
+ );
+ }
+ $this->mName = $p['dbname'];
+ parent::__construct( $p );
// parent doesn't open when $user is false, but we can work
with $dbName
- if ( $dbName && !$this->isOpen() ) {
- global $wgSharedDB;
- if ( $this->open( $server, $user, $password, $dbName )
&& $wgSharedDB ) {
- $this->attachDatabase( $wgSharedDB );
+ if ( $p['dbname'] && !$this->isOpen() ) {
+ if ( $this->open( $p['host'], $p['user'],
$p['password'], $p['dbname'] ) ) {
+ if ( $wgSharedDB ) {
+ $this->attachDatabase( $wgSharedDB );
+ }
}
}
}
diff --git a/tests/phpunit/includes/db/DatabaseMysqlBaseTest.php
b/tests/phpunit/includes/db/DatabaseMysqlBaseTest.php
index 134f856..636e488 100644
--- a/tests/phpunit/includes/db/DatabaseMysqlBaseTest.php
+++ b/tests/phpunit/includes/db/DatabaseMysqlBaseTest.php
@@ -31,6 +31,7 @@
*/
class FakeDatabaseMysqlBase extends DatabaseMysqlBase {
// From DatabaseBase
+ function __construct() {}
protected function closeConnection() {}
protected function doQuery( $sql ) {}
--
To view, visit https://gerrit.wikimedia.org/r/90653
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I094185585dc844ca4d2d8b629107b2ab8f9bef39
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Chad <[email protected]>
Gerrit-Reviewer: Liangent <[email protected]>
Gerrit-Reviewer: Parent5446 <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits