X-Git-Url: http://git.cyclocoop.org///%22%40url%40//%22?a=blobdiff_plain;f=includes%2Flibs%2Frdbms%2Fdatabase%2FDatabase.php;h=d22ecd0c8ec9f569fa18d5862579debccd99b17a;hb=6e6396d75e02b86d8b682404840c43684f9233c4;hp=38f51d3f59b15eaeb893a0b390eddd8f512b6bf8;hpb=8904dea2aa91d45bfd7f02c9343181e605f932f8;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/libs/rdbms/database/Database.php b/includes/libs/rdbms/database/Database.php index 38f51d3f59..d22ecd0c8e 100644 --- a/includes/libs/rdbms/database/Database.php +++ b/includes/libs/rdbms/database/Database.php @@ -79,7 +79,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware /** @var callback Error logging callback */ protected $errorLogger; - /** @var resource Database connection */ + /** @var resource|null Database connection */ protected $mConn = null; /** @var bool */ protected $mOpened = false; @@ -383,7 +383,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware } if ( !isset( $p['errorLogger'] ) ) { $p['errorLogger'] = function ( Exception $e ) { - trigger_error( get_class( $e ) . ': ' . $e->getMessage(), E_WARNING ); + trigger_error( get_class( $e ) . ': ' . $e->getMessage(), E_USER_WARNING ); }; } @@ -779,8 +779,11 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware * @return bool */ protected function isTransactableQuery( $sql ) { - $verb = $this->getQueryVerb( $sql ); - return !in_array( $verb, [ 'BEGIN', 'COMMIT', 'ROLLBACK', 'SHOW', 'SET' ], true ); + return !in_array( + $this->getQueryVerb( $sql ), + [ 'BEGIN', 'COMMIT', 'ROLLBACK', 'SHOW', 'SET', 'CREATE', 'ALTER' ], + true + ); } /** @@ -2834,7 +2837,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware $fnames = implode( ', ', $this->pendingWriteAndCallbackCallers() ); throw new DBUnexpectedError( $this, - "$fname: Cannot COMMIT to clear snapshot because writes are pending ($fnames)." + "$fname: Cannot flush snapshot because writes are pending ($fnames)." ); } @@ -3255,7 +3258,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware $fnames = implode( ', ', $this->pendingWriteAndCallbackCallers() ); throw new DBUnexpectedError( $this, - "$fname: Cannot COMMIT to clear snapshot because writes are pending ($fnames)." + "$fname: Cannot flush pre-lock snapshot because writes are pending ($fnames)." ); } @@ -3374,6 +3377,28 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware return true; } + /** + * Get the underlying binding handle, mConn + * + * Makes sure that mConn is set (disconnects and ping() failure can unset it). + * This catches broken callers than catch and ignore disconnection exceptions. + * Unlike checking isOpen(), this is safe to call inside of open(). + * + * @return resource|object + * @throws DBUnexpectedError + * @since 1.26 + */ + protected function getBindingHandle() { + if ( !$this->mConn ) { + throw new DBUnexpectedError( + $this, + 'DB connection was already closed or the connection dropped.' + ); + } + + return $this->mConn; + } + /** * @since 1.19 * @return string @@ -3428,8 +3453,11 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware } if ( $this->mConn ) { - // Avoid connection leaks for sanity + // Avoid connection leaks for sanity. Normally, resources close at script completion. + // The connection might already be closed in zend/hhvm by now, so suppress warnings. + \MediaWiki\suppressWarnings(); $this->closeConnection(); + \MediaWiki\restoreWarnings(); $this->mConn = false; $this->mOpened = false; }