From: Max Semenik Date: Tue, 28 Feb 2012 14:42:08 +0000 (+0000) Subject: Follow-up r112565: fix code duplication X-Git-Tag: 1.31.0-rc.0~24468 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=a8f718267ed535206d83f840dd98832223f4c356;p=lhc%2Fweb%2Fwiklou.git Follow-up r112565: fix code duplication --- diff --git a/includes/db/Database.php b/includes/db/Database.php index 896117bcf0..8c97bb595c 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -733,11 +733,27 @@ abstract class DatabaseBase implements DatabaseType { * * @return Bool operation success. true if already closed. */ - function close() { - # Stub, should probably be overridden - return true; + public function close() { + $this->mOpened = false; + if ( $this->mConn ) { + if ( $this->trxLevel() ) { + $this->commit( __METHOD__ ); + } + $ret = $this->closeConnection(); + $this->mConn = false; + return $ret; + } else { + return true; + } } + /** + * Closes underlying database connection + * @since 1.20 + * @return bool: Whether connection was closed successfully + */ + protected abstract function closeConnection(); + /** * @param $error String: fallback error message, used if none is given by DB */ diff --git a/includes/db/DatabaseIbm_db2.php b/includes/db/DatabaseIbm_db2.php index 83155b3d06..c9c311dc90 100644 --- a/includes/db/DatabaseIbm_db2.php +++ b/includes/db/DatabaseIbm_db2.php @@ -557,18 +557,8 @@ class DatabaseIbm_db2 extends DatabaseBase { * Returns success, true if already closed * @return bool */ - public function close() { - $this->mOpened = false; - if ( $this->mConn ) { - if ( $this->trxLevel() > 0 ) { - $this->commit( __METHOD__ ); - } - $ret = db2_close( $this->mConn ); - $this->mConn = null; - return $ret; - } else { - return true; - } + protected function closeConnection() { + return db2_close( $this->mConn ); } /** diff --git a/includes/db/DatabaseMssql.php b/includes/db/DatabaseMssql.php index 4b7dab2658..61963b6edf 100644 --- a/includes/db/DatabaseMssql.php +++ b/includes/db/DatabaseMssql.php @@ -110,15 +110,8 @@ class DatabaseMssql extends DatabaseBase { * Returns success, true if already closed * @return bool */ - function close() { - $this->mOpened = false; - if ( $this->mConn ) { - $ret = sqlsrv_close( $this->mConn ); - $this->mConn = null; - return $ret; - } else { - return true; - } + protected function closeConnection() { + return sqlsrv_close( $this->mConn ); } protected function doQuery( $sql ) { diff --git a/includes/db/DatabaseMysql.php b/includes/db/DatabaseMysql.php index 808cb48ca8..4fce0a5be9 100644 --- a/includes/db/DatabaseMysql.php +++ b/includes/db/DatabaseMysql.php @@ -154,18 +154,8 @@ class DatabaseMysql extends DatabaseBase { /** * @return bool */ - function close() { - $this->mOpened = false; - if ( $this->mConn ) { - if ( $this->trxLevel() ) { - $this->commit( __METHOD__ ); - } - $ret = mysql_close( $this->mConn ); - $this->mConn = false; - return $ret; - } else { - return true; - } + protected function closeConnection() { + return mysql_close( $this->mConn ); } /** diff --git a/includes/db/DatabaseOracle.php b/includes/db/DatabaseOracle.php index d3527ad023..58cb28b4b6 100644 --- a/includes/db/DatabaseOracle.php +++ b/includes/db/DatabaseOracle.php @@ -288,18 +288,8 @@ class DatabaseOracle extends DatabaseBase { * Returns success, true if already closed * @return bool */ - function close() { - $this->mOpened = false; - if ( $this->mConn ) { - if ( $this->mTrxLevel ) { - $this->commit( __METHOD__ ); - } - $ret = oci_close( $this->mConn ); - $this->mConn = null; - return null; - } else { - return true; - } + protected function closeConnection() { + return oci_close( $this->mConn ); } function execFlags() { diff --git a/includes/db/DatabasePostgres.php b/includes/db/DatabasePostgres.php index 2e1c6b7a4a..893b651011 100644 --- a/includes/db/DatabasePostgres.php +++ b/includes/db/DatabasePostgres.php @@ -240,15 +240,8 @@ class DatabasePostgres extends DatabaseBase { * Returns success, true if already closed * @return bool */ - function close() { - $this->mOpened = false; - if ( $this->mConn ) { - $ret = pg_close( $this->mConn ); - $this->mConn = null; - return $ret; - } else { - return true; - } + protected function closeConnection() { + return pg_close( $this->mConn ); } protected function doQuery( $sql ) { diff --git a/includes/db/DatabaseSqlite.php b/includes/db/DatabaseSqlite.php index 1cc82cf2bf..3aa21b84fe 100644 --- a/includes/db/DatabaseSqlite.php +++ b/includes/db/DatabaseSqlite.php @@ -115,16 +115,11 @@ class DatabaseSqlite extends DatabaseBase { } /** - * Close an SQLite database - * + * Does not actually close the connection, just destroys the reference for GC to do its work * @return bool */ - function close() { - $this->mOpened = false; - if ( is_object( $this->mConn ) ) { - if ( $this->trxLevel() ) $this->commit( __METHOD__ ); - $this->mConn = null; - } + protected function closeConnection() { + $this->mConn = null; return true; }