Get rid of a bunch of $wgDBtypes in maintenance/
authorChad Horohoe <demon@users.mediawiki.org>
Fri, 10 Dec 2010 13:56:17 +0000 (13:56 +0000)
committerChad Horohoe <demon@users.mediawiki.org>
Fri, 10 Dec 2010 13:56:17 +0000 (13:56 +0000)
maintenance/rebuildall.php
maintenance/rebuildtextindex.php
maintenance/sqlite.php
maintenance/tests/parser/parserTest.inc
maintenance/tests/parserTests.php
maintenance/tests/testHelpers.inc
maintenance/upgrade1_5.php

index 1dcd9a7..3d2aebc 100644 (file)
@@ -30,9 +30,8 @@ class RebuildAll extends Maintenance {
        }
 
        public function execute() {
-               global $wgDBtype;
                // Rebuild the text index
-               if ( $wgDBtype != 'postgres' ) {
+               if ( wfGetDB( DB_SLAVE )->getType() != 'postgres' ) {
                        $this->output( "** Rebuilding fulltext search index (if you abort this will break searching; run this script again to fix):\n" );
                        $rebuildText = $this->runChild( 'RebuildTextIndex', 'rebuildtextindex.php' );
                        $rebuildText->execute();
index 10550ea..6c400bd 100644 (file)
@@ -40,10 +40,11 @@ class RebuildTextIndex extends Maintenance {
        }
 
        public function execute() {
-               global $wgTitle, $wgDBtype;
+               global $wgTitle;
 
                // Shouldn't be needed for Postgres
-               if ( $wgDBtype == 'postgres' ) {
+               $this->db = wfGetDB( DB_MASTER );
+               if ( $this->db->getType() == 'postgres' ) {
                        $this->error( "This script is not needed when using Postgres.\n", true );
                }
 
index 6a28328..e46b8e7 100644 (file)
@@ -41,20 +41,18 @@ class SqliteMaintenance extends Maintenance {
        }
 
        public function execute() {
-               global $wgDBtype;
-
                // Should work even if we use a non-SQLite database
                if ( $this->hasOption( 'check-syntax' ) ) {
                        $this->checkSyntax();
                }
 
-               if ( $wgDBtype != 'sqlite' ) {
+               $this->db = wfGetDB( DB_MASTER );
+
+               if ( $this->db->getType() != 'sqlite' ) {
                        $this->error( "This maintenance script requires a SQLite database.\n" );
                        return;
                }
 
-               $this->db = wfGetDB( DB_MASTER );
-
                if ( $this->hasOption( 'vacuum' ) ) {
                        $this->vacuum();
                }
index 1474760..902133a 100644 (file)
@@ -723,13 +723,16 @@ class ParserTest {
         * the db will be visible to later tests in the run.
         */
        public function setupDatabase() {
-               global $wgDBprefix, $wgDBtype;
+               global $wgDBprefix;
 
                if ( $this->databaseSetupDone ) {
                        return;
                }
 
-               if ( $wgDBprefix === 'parsertest_' || ( $wgDBtype == 'oracle' && $wgDBprefix === 'pt_' ) ) {
+               $db = wfGetDB( DB_MASTER );
+               $dbType = $db->getType();
+
+               if ( $wgDBprefix === 'parsertest_' || ( $dbType == 'oracle' && $wgDBprefix === 'pt_' ) ) {
                        throw new MWException( 'setupDatabase should be called before setupGlobals' );
                }
 
@@ -745,9 +748,7 @@ class ParserTest {
                        $this->useTemporaryTables = false;
                }
 
-               $temporary = $this->useTemporaryTables || $wgDBtype == 'postgres';
-
-               $db = wfGetDB( DB_MASTER );
+               $temporary = $this->useTemporaryTables || $dbType == 'postgres';
                $tables = $this->listTables();
 
                foreach ( $tables as $tbl ) {
@@ -756,12 +757,12 @@ class ParserTest {
                        # fix back and forth so tableName() works right.
                        $this->changePrefix( $this->oldTablePrefix );
                        $oldTableName = $db->tableName( $tbl );
-                       $this->changePrefix( $wgDBtype != 'oracle' ? 'parsertest_' : 'pt_' );
+                       $this->changePrefix( $dbType != 'oracle' ? 'parsertest_' : 'pt_' );
                        $newTableName = $db->tableName( $tbl );
 
-                       if ( $wgDBtype == 'mysql' ) {
+                       if ( $dbType == 'mysql' ) {
                                $db->query( "DROP TABLE IF EXISTS $newTableName" );
-                       } elseif ( in_array( $wgDBtype, array( 'postgres', 'oracle' ) ) ) {
+                       } elseif ( in_array( $dbType, array( 'postgres', 'oracle' ) ) ) {
                                /* DROPs wouldn't work due to Foreign Key Constraints (bug 14990, r58669)
                                 * Use "DROP TABLE IF EXISTS $newTableName CASCADE" for postgres? That
                                 * syntax would also work for mysql.
@@ -774,12 +775,12 @@ class ParserTest {
                        $db->duplicateTableStructure( $oldTableName, $newTableName, $temporary );
                }
 
-               if ( $wgDBtype == 'oracle' )
+               if ( $dbType == 'oracle' )
                        $db->query( 'BEGIN FILL_WIKI_INFO; END;' );
 
-               $this->changePrefix( $wgDBtype != 'oracle' ? 'parsertest_' : 'pt_' );
+               $this->changePrefix( $dbType != 'oracle' ? 'parsertest_' : 'pt_' );
 
-               if ( $wgDBtype == 'oracle' ) {
+               if ( $dbType == 'oracle' ) {
                        # Insert 0 user to prevent FK violations
 
                        # Anonymous user
@@ -882,8 +883,6 @@ class ParserTest {
        }
 
        public function teardownDatabase() {
-               global $wgDBtype;
-
                if ( !$this->databaseSetupDone ) {
                        $this->teardownGlobals();
                        return;
@@ -903,11 +902,11 @@ class ParserTest {
                $db = wfGetDB( DB_MASTER );
 
                foreach ( $tables as $table ) {
-                       $sql = $wgDBtype == 'oracle' ? "DROP TABLE pt_$table DROP CONSTRAINTS" : "DROP TABLE `parsertest_$table`";
+                       $sql = $db->getType() == 'oracle' ? "DROP TABLE pt_$table DROP CONSTRAINTS" : "DROP TABLE `parsertest_$table`";
                        $db->query( $sql );
                }
 
-               if ( $wgDBtype == 'oracle' )
+               if ( $db->getType() == 'oracle' )
                        $db->query( 'BEGIN FILL_WIKI_INFO; END;' );
 
                $this->teardownGlobals();
index 7793e6b..bc32816 100644 (file)
@@ -59,9 +59,8 @@ ENDS;
 
 # Cases of weird db corruption were encountered when running tests on earlyish
 # versions of SQLite
-if ( $wgDBtype == 'sqlite' ) {
-       $db = wfGetDB( DB_MASTER );
-       $version = $db->getServerVersion();
+if ( wfGetDB( DB_MASTER )->getType() == 'sqlite' ) {
+       $version = wfGetDB( DB_MASTER )->getServerVersion();
        if ( version_compare( $version, '3.6' ) < 0 ) {
                die( "Parser tests require SQLite version 3.6 or later, you have $version\n" );
        }
index 94ca6ab..dc8b0fa 100644 (file)
@@ -302,7 +302,6 @@ class DbTestRecorder extends DbTestPreviewer  {
         * and all that fun stuff
         */
        function start() {
-               global $wgDBtype;
                $this->db->begin();
 
                if ( ! $this->db->tableExists( 'testrun' )
@@ -324,7 +323,7 @@ class DbTestRecorder extends DbTestPreviewer  {
                                'tr_uname'       => php_uname()
                        ),
                        __METHOD__ );
-                       if ( $wgDBtype === 'postgres' ) {
+                       if ( $this->db->getType() === 'postgres' ) {
                                $this->curRun = $this->db->currentSequenceValue( 'testrun_id_seq' );
                        } else {
                                $this->curRun = $this->db->insertId();
index 20429eb..d26bfd6 100644 (file)
@@ -125,12 +125,10 @@ class FiveUpgrade extends Maintenance {
         * @access private
         */
        function streamConnection() {
-               global $wgDBtype;
-
                $timeout = 3600 * 24;
                $db = $this->newConnection();
                $db->bufferResults( false );
-               if ( $wgDBtype == 'mysql' ) {
+               if ( $db->getType() == 'mysql' ) {
                        $db->query( "SET net_read_timeout=$timeout" );
                        $db->query( "SET net_write_timeout=$timeout" );
                }