[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Avoid MWException and wf* log methods in DatabaseBase

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

Change subject: Avoid MWException and wf* log methods in DatabaseBase
..


Avoid MWException and wf* log methods in DatabaseBase

Change-Id: Idc418ae1088f87d6416e2552976d94f7d1e8f5db
---
M includes/db/Database.php
M includes/db/DatabaseMssql.php
M includes/db/DatabaseSqlite.php
M includes/db/loadbalancer/LBFactoryMulti.php
M includes/db/loadbalancer/LBFactorySimple.php
M includes/libs/rdbms/loadbalancer/LoadBalancer.php
6 files changed, 35 insertions(+), 35 deletions(-)

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



diff --git a/includes/db/Database.php b/includes/db/Database.php
index e68a8f2..0c357cc 100644
--- a/includes/db/Database.php
+++ b/includes/db/Database.php
@@ -69,6 +69,8 @@
protected $connLogger;
/** @var LoggerInterface */
protected $queryLogger;
+   /** @var callback Error logging callback */
+   protected $errorLogger;
 
/** @var resource Database connection */
protected $mConn = null;
@@ -319,7 +321,7 @@
 * @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
-* @throws MWException
+* @throws InvalidArgumentException If the database driver or extension 
cannot be found
 */
final public static function factory( $dbType, $p = [] ) {
global $wgCommandLineMode;
@@ -355,7 +357,7 @@
$driver = $dbType;
}
if ( $driver === false ) {
-   throw new MWException( __METHOD__ .
+   throw new InvalidArgumentException( __METHOD__ .
" no viable database extension found for type 
'$dbType'" );
}
 
@@ -389,6 +391,11 @@
}
if ( isset( $p['queryLogger'] ) ) {
$conn->queryLogger = $p['queryLogger'];
+   }
+   if ( isset( $p['errorLogger'] ) ) {
+   $conn->errorLogger = $p['errorLogger'];
+   } else {
+   $conn->errorLogger = [ 
MWExceptionHandler::class, 'logException' ];
}
} else {
$conn = null;
@@ -741,7 +748,7 @@
protected function installErrorHandler() {
$this->mPHPError = false;
$this->htmlErrors = ini_set( 'html_errors', '0' );
-   set_error_handler( [ $this, 'connectionErrorHandler' ] );
+   set_error_handler( [ $this, 'connectionerrorLogger' ] );
}
 
/**
@@ -766,12 +773,12 @@
 * @param int $errno
 * @param string $errstr
 */
-   public function connectionErrorHandler( $errno, $errstr ) {
+   public function connectionerrorLogger( $errno, $errstr ) {
$this->mPHPError = $errstr;
}
 
/**
-* Create a log context to pass to wfLogDBError or other logging 
functions.
+* Create a log context to pass to PSR logging functions.
 *
 * @param array $extras Additional data to add to context
 * @return array
@@ -790,11 +797,6 @@
public function close() {
if ( $this->mConn ) {
if ( $this->trxLevel() ) {
-   if ( !$this->mTrxAutomatic ) {
-   wfWarn( "Transaction still in progress 
(from {$this->mTrxFname}), " .
-   " performing implicit commit 
before closing connection!" );
-   }
-
$this->commit( __METHOD__, 
self::FLUSHING_INTERNAL );
}
 
@@ -948,7 +950,8 @@
if ( $this->reconnect() ) {
$msg = __METHOD__ . ": lost connection to 
{$this->getServer()}; reconnected";
$this->connLogger->warning( $msg );
-   $this->queryLogger->warning( "$msg:\n" . 
wfBacktrace( true ) );
+   $this->queryLogger->warning(
+   "$msg:\n" . ( new RuntimeException() 
)->getTraceAsString() );
 
if ( !$recoverable ) {
# Callers may catch the exception and 
continue to use the DB
@@ -1097,7 +1100,7 @@
$this->queryLogger->debug( "SQL ERROR (ignored): 
$error\n" );
} else {
$sql1line = mb_substr( str_replace( "\n", "\\n", $sql 
), 0, 5 * 1024 );
-   

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Avoid MWException and wf* log methods in DatabaseBase

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

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

Change subject: Avoid MWException and wf* log methods in DatabaseBase
..

Avoid MWException and wf* log methods in DatabaseBase

Change-Id: Idc418ae1088f87d6416e2552976d94f7d1e8f5db
---
M includes/db/Database.php
M includes/db/DatabaseMssql.php
M includes/db/DatabaseSqlite.php
M includes/db/loadbalancer/LBFactoryMulti.php
M includes/db/loadbalancer/LBFactorySimple.php
M includes/db/loadbalancer/LoadBalancer.php
6 files changed, 36 insertions(+), 36 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/20/310720/1

diff --git a/includes/db/Database.php b/includes/db/Database.php
index 109dbfe..17761ff 100644
--- a/includes/db/Database.php
+++ b/includes/db/Database.php
@@ -69,6 +69,8 @@
protected $connLogger;
/** @var LoggerInterface */
protected $queryLogger;
+   /** @var callback Error logging callback */
+   protected $errorLogger;
 
/** @var resource Database connection */
protected $mConn = null;
@@ -318,7 +320,7 @@
 * @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
-* @throws MWException If the database driver or extension cannot be 
found
+* @throws InvalidArgumentException If the database driver or extension 
cannot be found
 * @return DatabaseBase|null DatabaseBase subclass or null
 */
final public static function factory( $dbType, $p = [] ) {
@@ -355,7 +357,7 @@
$driver = $dbType;
}
if ( $driver === false ) {
-   throw new MWException( __METHOD__ .
+   throw new InvalidArgumentException( __METHOD__ .
" no viable database extension found for type 
'$dbType'" );
}
 
@@ -390,6 +392,11 @@
if ( isset( $p['queryLogger'] ) ) {
$conn->queryLogger = $p['queryLogger'];
}
+   if ( isset( $p['errorLogger'] ) ) {
+   $conn->errorLogger = $p['errorLogger'];
+   } else {
+   $conn->errorLogger = [ 
MWExceptionHandler::class, 'logException' ];
+   }
} else {
$conn = null;
}
@@ -398,7 +405,7 @@
}
 
public function setLogger( LoggerInterface $logger ) {
-   $this->quertLogger = $logger;
+   $this->queryLogger = $logger;
}
 
public function getServerInfo() {
@@ -747,7 +754,7 @@
protected function installErrorHandler() {
$this->mPHPError = false;
$this->htmlErrors = ini_set( 'html_errors', '0' );
-   set_error_handler( [ $this, 'connectionErrorHandler' ] );
+   set_error_handler( [ $this, 'connectionerrorLogger' ] );
}
 
/**
@@ -772,12 +779,12 @@
 * @param int $errno
 * @param string $errstr
 */
-   public function connectionErrorHandler( $errno, $errstr ) {
+   public function connectionerrorLogger( $errno, $errstr ) {
$this->mPHPError = $errstr;
}
 
/**
-* Create a log context to pass to wfLogDBError or other logging 
functions.
+* Create a log context to pass to PSR logging functions.
 *
 * @param array $extras Additional data to add to context
 * @return array
@@ -796,11 +803,6 @@
public function close() {
if ( $this->mConn ) {
if ( $this->trxLevel() ) {
-   if ( !$this->mTrxAutomatic ) {
-   wfWarn( "Transaction still in progress 
(from {$this->mTrxFname}), " .
-   " performing implicit commit 
before closing connection!" );
-   }
-
$this->commit( __METHOD__, 
self::FLUSHING_INTERNAL );
}
 
@@ -954,7 +956,8 @@
if ( $this->reconnect() ) {
$msg = __METHOD__ . ": lost connection to 
{$this->getServer()}; reconnected";
$this->connLogger->warning( $msg );
-   $this->queryLogger->warning( "$msg:\n" . 
wfBacktrace( true ) );
+   $this->queryLogger->warning(
+   "$msg:\n" . ( new RuntimeException() 
)->getTraceAsString() );
 
if ( !$recoverable ) {
# Callers may