[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Database class parameter and documentation cleanups

2016-09-19 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Database class parameter and documentation cleanups
..


Database class parameter and documentation cleanups

* Document various parameter arrays.
* Fix $user = false loophole in Database::__construct().
* Set the Postgres port *before* calling super, as it is
  needed by open().
* Remove 'chronProt' parameter as it is lazy-loaded.

Change-Id: Icc1037efa1eee7ae6fdd2919f60001e6e29ae55c
---
M includes/libs/rdbms/database/Database.php
M includes/libs/rdbms/database/DatabasePostgres.php
M includes/libs/rdbms/database/DatabaseSqlite.php
M includes/libs/rdbms/lbfactory/LBFactory.php
M includes/libs/rdbms/lbfactory/LBFactoryMulti.php
M includes/libs/rdbms/lbfactory/LBFactorySimple.php
M includes/libs/rdbms/loadbalancer/ILoadBalancer.php
7 files changed, 156 insertions(+), 94 deletions(-)

Approvals:
  Tim Starling: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/libs/rdbms/database/Database.php 
b/includes/libs/rdbms/database/Database.php
index f9e9296..a5b9284 100644
--- a/includes/libs/rdbms/database/Database.php
+++ b/includes/libs/rdbms/database/Database.php
@@ -231,16 +231,12 @@
protected $trxProfiler;
 
/**
-* Constructor.
-*
-* FIXME: It is possible to construct a Database object with no 
associated
-* connection object, by specifying no parameters to __construct(). This
-* feature is deprecated and should be removed.
+* Constructor and database handle and attempt to connect to the DB 
server
 *
 * IDatabase classes should not be constructed directly in external
-* code. DatabaseBase::factory() should be used instead.
+* code. Database::factory() should be used instead.
 *
-* @param array $params Parameters passed from DatabaseBase::factory()
+* @param array $params Parameters passed from Database::factory()
 */
function __construct( array $params ) {
$server = $params['host'];
@@ -287,37 +283,59 @@
 
if ( $user ) {
$this->open( $server, $user, $password, $dbName );
+   } elseif ( $this->requiresDatabaseUser() ) {
+   throw new InvalidArgumentException( "No database user 
provided." );
}
 
+   // Set the domain object after open() sets the relevant fields
$this->currentDomain = ( $this->mDBname != '' )
? new DatabaseDomain( $this->mDBname, null, 
$this->mTablePrefix )
: DatabaseDomain::newUnspecified();
}
 
/**
-* Given a DB type, construct the name of the appropriate child class of
-* IDatabase. This is designed to replace all of the manual stuff like:
-*$class = 'Database' . ucfirst( strtolower( $dbType ) );
-* as well as validate against the canonical list of DB types we have
+* Construct a Database subclass instance given a database type and 
parameters
 *
-* This factory function is mostly useful for when you need to connect 
to a
-* database other than the MediaWiki default (such as for external auth,
-* an extension, et cetera). Do not use this to connect to the MediaWiki
-* database. Example uses in core:
-* @see LoadBalancer::reallyOpenConnection()
-* @see ForeignDBRepo::getMasterDB()
-* @see WebInstallerDBConnect::execute()
+* This also connects to the database immediately upon object 
construction
 *
-* @since 1.18
-*
-* @param string $dbType A possible DB type
-* @param array $p An array of options to pass to the constructor.
-*Valid options are: host, user, password, dbname, flags, 
tablePrefix, schema, driver
-* @return IDatabase|null If the database driver or extension cannot be 
found
+* @param string $dbType A possible DB type (sqlite, mysql, postgres)
+* @param array $p Parameter map with keys:
+*   - host : The hostname of the DB server
+*   - user : The name of the database user the client operates under
+*   - password : The password for the database user
+*   - dbname : The name of the database to use where queries do not 
specify one.
+*  The database must exist or an error might be thrown. Setting 
this to the empty string
+*  will avoid any such errors and make the handle have no implicit 
database scope. This is
+*  useful for queries like SHOW STATUS, CREATE DATABASE, or DROP 
DATABASE. Note that a
+*  "database" in Postgres is rougly equivalent to an entire MySQL 
server. This the domain
+*  in which user names and such are defined, e.g. users are 
database-specific in Postgres.
+*   - schema : The d

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Database class parameter and documentation cleanups

2016-09-19 Thread Aaron Schulz (Code Review)
Aaron Schulz has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/311629

Change subject: Database class parameter and documentation cleanups
..

Database class parameter and documentation cleanups

Change-Id: Icc1037efa1eee7ae6fdd2919f60001e6e29ae55c
---
M includes/libs/rdbms/database/Database.php
M includes/libs/rdbms/lbfactory/LBFactory.php
M includes/libs/rdbms/lbfactory/LBFactoryMulti.php
M includes/libs/rdbms/lbfactory/LBFactorySimple.php
M includes/libs/rdbms/loadbalancer/ILoadBalancer.php
5 files changed, 143 insertions(+), 93 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/29/311629/1

diff --git a/includes/libs/rdbms/database/Database.php 
b/includes/libs/rdbms/database/Database.php
index f9e9296..fd5cc25 100644
--- a/includes/libs/rdbms/database/Database.php
+++ b/includes/libs/rdbms/database/Database.php
@@ -231,16 +231,12 @@
protected $trxProfiler;
 
/**
-* Constructor.
-*
-* FIXME: It is possible to construct a Database object with no 
associated
-* connection object, by specifying no parameters to __construct(). This
-* feature is deprecated and should be removed.
+* Constructor and database handle and attempt to connect to the DB 
server
 *
 * IDatabase classes should not be constructed directly in external
-* code. DatabaseBase::factory() should be used instead.
+* code. Database::factory() should be used instead.
 *
-* @param array $params Parameters passed from DatabaseBase::factory()
+* @param array $params Parameters passed from Database::factory()
 */
function __construct( array $params ) {
$server = $params['host'];
@@ -285,39 +281,60 @@
? $params['queryLogger']
: new \Psr\Log\NullLogger();
 
-   if ( $user ) {
-   $this->open( $server, $user, $password, $dbName );
+   if ( !$user ) {
+   throw new InvalidArgumentException( "No database user 
provided." );
}
 
+   $this->open( $server, $user, $password, $dbName );
+   // Set the domain object after open() sets the relevant fields
$this->currentDomain = ( $this->mDBname != '' )
? new DatabaseDomain( $this->mDBname, null, 
$this->mTablePrefix )
: DatabaseDomain::newUnspecified();
}
 
/**
-* Given a DB type, construct the name of the appropriate child class of
-* IDatabase. This is designed to replace all of the manual stuff like:
-*$class = 'Database' . ucfirst( strtolower( $dbType ) );
-* as well as validate against the canonical list of DB types we have
+* Construct a Database subclass instance given a database type and 
parameters
 *
-* This factory function is mostly useful for when you need to connect 
to a
-* database other than the MediaWiki default (such as for external auth,
-* an extension, et cetera). Do not use this to connect to the MediaWiki
-* database. Example uses in core:
-* @see LoadBalancer::reallyOpenConnection()
-* @see ForeignDBRepo::getMasterDB()
-* @see WebInstallerDBConnect::execute()
+* This also connects to the database immediately upon object 
construction
 *
-* @since 1.18
-*
-* @param string $dbType A possible DB type
-* @param array $p An array of options to pass to the constructor.
-*Valid options are: host, user, password, dbname, flags, 
tablePrefix, schema, driver
-* @return IDatabase|null If the database driver or extension cannot be 
found
+* @param string $dbType A possible DB type (sqlite, mysql, postgres)
+* @param array $p Parameter map with keys:
+*   - host : The hostname of the DB server
+*   - user : The name of the database user the client operates under
+*   - password : The password for the database user
+*   - dbname : The name of the database to use where queries do not 
specify one.
+*  The database must exist or an error might be thrown. Setting 
this to the empty string
+*  will avoid any such errors and make the handle have no implicit 
database scope. This is
+*  useful for queries like SHOW STATUS, CREATE DATABASE, or DROP 
DATABASE. Note that a
+*  "database" in Postgres is rougly equivalent to an entire MySQL 
server. This the domain
+*  in which user names and such are defined, e.g. users are 
database-specific in Postgres.
+*   - schema : The database schema to use (if supported). A "schema" 
in Postgres is roughly
+*  equivalent to a "database" in MySQL. Note that MySQL and S