* Cleanup massive duplication across Database constructors. Default implementation...
authorChad Horohoe <demon@users.mediawiki.org>
Mon, 24 Jan 2011 18:36:09 +0000 (18:36 +0000)
committerChad Horohoe <demon@users.mediawiki.org>
Mon, 24 Jan 2011 18:36:09 +0000 (18:36 +0000)
* Get rid of intermediate installTables() callback
* Actually cache the result of DbInstaller::getConnection() like the documentation says

includes/db/DatabaseIbm_db2.php
includes/db/DatabaseMssql.php
includes/db/DatabaseOracle.php
includes/db/DatabasePostgres.php
includes/db/DatabaseSqlite.php
includes/installer/DatabaseInstaller.php
includes/installer/Installer.php
includes/installer/MysqlInstaller.php
includes/installer/PostgresInstaller.php
includes/installer/SqliteInstaller.php

index ad2862e..329bc6d 100644 (file)
@@ -264,14 +264,6 @@ class DatabaseIbm_db2 extends DatabaseBase {
                                                        $dbName = false, $flags = 0,
                                                        $schema = self::USE_GLOBAL )
        {
-
-               global $wgOut, $wgDBmwschema;
-               # Can't get a reference if it hasn't been set yet
-               if ( !isset( $wgOut ) ) {
-                       $wgOut = null;
-               }
-               $this->mFlags = DBO_TRX | $flags;
-
                if ( $schema == self::USE_GLOBAL ) {
                        $this->mSchema = $wgDBmwschema;
                } else {
@@ -286,7 +278,7 @@ class DatabaseIbm_db2 extends DatabaseBase {
                $this->setDB2Option( 'rowcount', 'DB2_ROWCOUNT_PREFETCH_ON',
                        self::STMT_OPTION );
 
-               $this->open( $server, $user, $password, $dbName );
+               parent::__construct( $server, $user, $password, $dbName, $flags );
        }
 
        /**
index 5b3b335..af263c7 100644 (file)
@@ -17,13 +17,6 @@ class DatabaseMssql extends DatabaseBase {
        var $mLastResult = NULL;
        var $mAffectedRows = NULL;
 
-       function __construct( $server = false, $user = false, $password = false, $dbName = false,
-               $flags = 0 )
-       {
-               $this->mFlags = $flags;
-               $this->open( $server, $user, $password, $dbName );
-       }
-
        function cascadingDeletes() {
                return true;
        }
index 43ca21e..10a566b 100644 (file)
@@ -182,7 +182,7 @@ class DatabaseOracle extends DatabaseBase {
        {
                $tablePrefix = $tablePrefix == 'get from global' ? $tablePrefix : strtoupper( $tablePrefix );
                parent::__construct( $server, $user, $password, $dbName, $flags, $tablePrefix );
-               wfRunHooks( 'DatabaseOraclePostInit', array( &$this ) );
+               wfRunHooks( 'DatabaseOraclePostInit', array( $this ) );
        }
 
        function getType() {
index b36240f..151f632 100644 (file)
@@ -100,13 +100,6 @@ class DatabasePostgres extends DatabaseBase {
        var $numeric_version = null;
        var $mAffectedRows = null;
 
-       function __construct( $server = false, $user = false, $password = false, $dbName = false,
-               $flags = 0 )
-       {
-               $this->mFlags = $flags;
-               $this->open( $server, $user, $password, $dbName );
-       }
-
        function getType() {
                return 'postgres';
        }
index 7afccaf..60cede3 100644 (file)
@@ -24,12 +24,12 @@ class DatabaseSqlite extends DatabaseBase {
         * Parameters $server, $user and $password are not used.
         */
        function __construct( $server = false, $user = false, $password = false, $dbName = false, $flags = 0 ) {
-               global $wgSharedDB;
-               $this->mFlags = $flags;
                $this->mName = $dbName;
-
-               if( $server ) {
-                       if ( $this->open( $server, $user, $password, $dbName ) && $wgSharedDB ) {
+               parent::__construct( $server, $user, $password, $dbName, $flags );
+               // parent doesn't open when $server is false, but we can work with $dbName
+               if( !$server && $dbName ) {
+                       global $wgSharedDB;
+                       if( $this->open( $server, $user, $password, $dbName ) && $wgSharedDB ) {
                                $this->attachDatabase( $wgSharedDB );
                        }
                }
index dbdbccf..6c4c552 100644 (file)
@@ -28,7 +28,7 @@ abstract class DatabaseInstaller {
         *
         * @var DatabaseBase
         */
-       public $db;
+       public $db = null;
 
        /**
         * Internal variables for installation.
@@ -140,6 +140,10 @@ abstract class DatabaseInstaller {
                } else {
                        $this->db->commit( __METHOD__ );
                }
+               // Resume normal operations
+               if( $status->isOk() ) {
+                       LBFactory::enableBackend();
+               }
                return $status;
        }
 
index 25e9fb8..e836780 100644 (file)
@@ -555,23 +555,6 @@ abstract class Installer {
                $this->parserOptions->setExternalLinkTarget( $wgExternalLinkTarget );
        }
 
-       /**
-        * TODO: document
-        *
-        * @param $installer DatabaseInstaller
-        *
-        * @return Status
-        */
-       public function installTables( DatabaseInstaller &$installer ) {
-               $status = $installer->createTables();
-
-               if( $status->isOK() ) {
-                       LBFactory::enableBackend();
-               }
-
-               return $status;
-       }
-
        /**
         * Exports all wg* variables stored by the installer into global scope.
         */
@@ -1222,7 +1205,7 @@ abstract class Installer {
        protected function getInstallSteps( DatabaseInstaller &$installer ) {
                $coreInstallSteps = array(
                        array( 'name' => 'database',   'callback' => array( $installer, 'setupDatabase' ) ),
-                       array( 'name' => 'tables',     'callback' => array( $this, 'installTables' ) ),
+                       array( 'name' => 'tables',     'callback' => array( $installer, 'createTables' ) ),
                        array( 'name' => 'interwiki',  'callback' => array( $installer, 'populateInterwikiTable' ) ),
                        array( 'name' => 'secretkey',  'callback' => array( $this, 'generateSecretKey' ) ),
                        array( 'name' => 'upgradekey', 'callback' => array( $this, 'generateUpgradeKey' ) ),
index 57f44c1..aabacca 100644 (file)
@@ -113,19 +113,23 @@ class MysqlInstaller extends DatabaseInstaller {
 
        public function getConnection() {
                $status = Status::newGood();
-               try {
-                       $this->db = new DatabaseMysql(
-                               $this->getVar( 'wgDBserver' ),
-                               $this->getVar( '_InstallUser' ),
-                               $this->getVar( '_InstallPassword' ),
-                               false,
-                               false,
-                               0,
-                               $this->getVar( 'wgDBprefix' )
-                       );
+               if( is_null( $this->db ) ) {
+                       try {
+                               $this->db = new DatabaseMysql(
+                                       $this->getVar( 'wgDBserver' ),
+                                       $this->getVar( '_InstallUser' ),
+                                       $this->getVar( '_InstallPassword' ),
+                                       false,
+                                       false,
+                                       0,
+                                       $this->getVar( 'wgDBprefix' )
+                               );
+                               $status->value = $this->db;
+                       } catch ( DBConnectionError $e ) {
+                               $status->fatal( 'config-connection-error', $e->getMessage() );
+                       }
+               } else {
                        $status->value = $this->db;
-               } catch ( DBConnectionError $e ) {
-                       $status->fatal( 'config-connection-error', $e->getMessage() );
                }
                return $status;
        }
index e02dc27..3f7d5be 100644 (file)
@@ -100,16 +100,19 @@ class PostgresInstaller extends DatabaseInstaller {
 
        function getConnection($database = 'template1') {
                $status = Status::newGood();
-
-               try {
-                       $this->db = new DatabasePostgres(
-                               $this->getVar( 'wgDBserver' ),
-                               $this->getVar( '_InstallUser' ),
-                               $this->getVar( '_InstallPassword' ),
-                               $database );
+               if( is_null( $this->db ) ) {
+                       try {
+                               $this->db = new DatabasePostgres(
+                                       $this->getVar( 'wgDBserver' ),
+                                       $this->getVar( '_InstallUser' ),
+                                       $this->getVar( '_InstallPassword' ),
+                                       $database );
+                               $status->value = $this->db;
+                       } catch ( DBConnectionError $e ) {
+                               $status->fatal( 'config-connection-error', $e->getMessage() );
+                       }
+               } else {
                        $status->value = $this->db;
-               } catch ( DBConnectionError $e ) {
-                       $status->fatal( 'config-connection-error', $e->getMessage() );
                }
                return $status;
        }
index 9393d83..32d22e6 100644 (file)
@@ -93,17 +93,21 @@ class SqliteInstaller extends DatabaseInstaller {
                global $wgSQLiteDataDir;
 
                $status = Status::newGood();
-               $dir = $this->getVar( 'wgSQLiteDataDir' );
-               $dbName = $this->getVar( 'wgDBname' );
-
-               try {
-                       # FIXME: need more sensible constructor parameters, e.g. single associative array
-                       # Setting globals kind of sucks
-                       $wgSQLiteDataDir = $dir;
-                       $this->db = new DatabaseSqlite( false, false, false, $dbName );
+               if( is_null( $this->db ) ) {
+                       $dir = $this->getVar( 'wgSQLiteDataDir' );
+                       $dbName = $this->getVar( 'wgDBname' );
+
+                       try {
+                               # FIXME: need more sensible constructor parameters, e.g. single associative array
+                               # Setting globals kind of sucks
+                               $wgSQLiteDataDir = $dir;
+                               $this->db = new DatabaseSqlite( false, false, false, $dbName );
+                               $status->value = $this->db;
+                       } catch ( DBConnectionError $e ) {
+                               $status->fatal( 'config-sqlite-connection-error', $e->getMessage() );
+                       }
+               } else {
                        $status->value = $this->db;
-               } catch ( DBConnectionError $e ) {
-                       $status->fatal( 'config-sqlite-connection-error', $e->getMessage() );
                }
                return $status;
        }