https://www.mediawiki.org/wiki/Special:Code/MediaWiki/112598

Revision: 112598
Author:   maxsem
Date:     2012-02-28 14:42:08 +0000 (Tue, 28 Feb 2012)
Log Message:
-----------
Follow-up r112565: fix code duplication

Modified Paths:
--------------
    trunk/phase3/includes/db/Database.php
    trunk/phase3/includes/db/DatabaseIbm_db2.php
    trunk/phase3/includes/db/DatabaseMssql.php
    trunk/phase3/includes/db/DatabaseMysql.php
    trunk/phase3/includes/db/DatabaseOracle.php
    trunk/phase3/includes/db/DatabasePostgres.php
    trunk/phase3/includes/db/DatabaseSqlite.php

Modified: trunk/phase3/includes/db/Database.php
===================================================================
--- trunk/phase3/includes/db/Database.php       2012-02-28 14:29:16 UTC (rev 
112597)
+++ trunk/phase3/includes/db/Database.php       2012-02-28 14:42:08 UTC (rev 
112598)
@@ -733,12 +733,28 @@
         *
         * @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
         */
        function reportConnectionError( $error = 'Unknown error' ) {

Modified: trunk/phase3/includes/db/DatabaseIbm_db2.php
===================================================================
--- trunk/phase3/includes/db/DatabaseIbm_db2.php        2012-02-28 14:29:16 UTC 
(rev 112597)
+++ trunk/phase3/includes/db/DatabaseIbm_db2.php        2012-02-28 14:42:08 UTC 
(rev 112598)
@@ -557,18 +557,8 @@
         * 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 );
        }
 
        /**

Modified: trunk/phase3/includes/db/DatabaseMssql.php
===================================================================
--- trunk/phase3/includes/db/DatabaseMssql.php  2012-02-28 14:29:16 UTC (rev 
112597)
+++ trunk/phase3/includes/db/DatabaseMssql.php  2012-02-28 14:42:08 UTC (rev 
112598)
@@ -110,15 +110,8 @@
         * 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 ) {

Modified: trunk/phase3/includes/db/DatabaseMysql.php
===================================================================
--- trunk/phase3/includes/db/DatabaseMysql.php  2012-02-28 14:29:16 UTC (rev 
112597)
+++ trunk/phase3/includes/db/DatabaseMysql.php  2012-02-28 14:42:08 UTC (rev 
112598)
@@ -154,18 +154,8 @@
        /**
         * @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 );
        }
 
        /**

Modified: trunk/phase3/includes/db/DatabaseOracle.php
===================================================================
--- trunk/phase3/includes/db/DatabaseOracle.php 2012-02-28 14:29:16 UTC (rev 
112597)
+++ trunk/phase3/includes/db/DatabaseOracle.php 2012-02-28 14:42:08 UTC (rev 
112598)
@@ -288,18 +288,8 @@
         * 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() {

Modified: trunk/phase3/includes/db/DatabasePostgres.php
===================================================================
--- trunk/phase3/includes/db/DatabasePostgres.php       2012-02-28 14:29:16 UTC 
(rev 112597)
+++ trunk/phase3/includes/db/DatabasePostgres.php       2012-02-28 14:42:08 UTC 
(rev 112598)
@@ -240,15 +240,8 @@
         * 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 ) {

Modified: trunk/phase3/includes/db/DatabaseSqlite.php
===================================================================
--- trunk/phase3/includes/db/DatabaseSqlite.php 2012-02-28 14:29:16 UTC (rev 
112597)
+++ trunk/phase3/includes/db/DatabaseSqlite.php 2012-02-28 14:42:08 UTC (rev 
112598)
@@ -115,16 +115,11 @@
        }
 
        /**
-        * 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;
        }
 


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to