r78183 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78182‎ | r78183 | r78184 >
Date:13:56, 10 December 2010
Author:demon
Status:ok
Tags:
Comment:
Get rid of a bunch of $wgDBtypes in maintenance/
Modified paths:
  • /trunk/phase3/maintenance/rebuildall.php (modified) (history)
  • /trunk/phase3/maintenance/rebuildtextindex.php (modified) (history)
  • /trunk/phase3/maintenance/sqlite.php (modified) (history)
  • /trunk/phase3/maintenance/tests/parser/parserTest.inc (modified) (history)
  • /trunk/phase3/maintenance/tests/parserTests.php (modified) (history)
  • /trunk/phase3/maintenance/tests/testHelpers.inc (modified) (history)
  • /trunk/phase3/maintenance/upgrade1_5.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/tests/parserTests.php
@@ -59,9 +59,8 @@
6060
6161 # Cases of weird db corruption were encountered when running tests on earlyish
6262 # versions of SQLite
63 -if ( $wgDBtype == 'sqlite' ) {
64 - $db = wfGetDB( DB_MASTER );
65 - $version = $db->getServerVersion();
 63+if ( wfGetDB( DB_MASTER )->getType() == 'sqlite' ) {
 64+ $version = wfGetDB( DB_MASTER )->getServerVersion();
6665 if ( version_compare( $version, '3.6' ) < 0 ) {
6766 die( "Parser tests require SQLite version 3.6 or later, you have $version\n" );
6867 }
Index: trunk/phase3/maintenance/tests/testHelpers.inc
@@ -302,7 +302,6 @@
303303 * and all that fun stuff
304304 */
305305 function start() {
306 - global $wgDBtype;
307306 $this->db->begin();
308307
309308 if ( ! $this->db->tableExists( 'testrun' )
@@ -324,7 +323,7 @@
325324 'tr_uname' => php_uname()
326325 ),
327326 __METHOD__ );
328 - if ( $wgDBtype === 'postgres' ) {
 327+ if ( $this->db->getType() === 'postgres' ) {
329328 $this->curRun = $this->db->currentSequenceValue( 'testrun_id_seq' );
330329 } else {
331330 $this->curRun = $this->db->insertId();
Index: trunk/phase3/maintenance/tests/parser/parserTest.inc
@@ -723,13 +723,16 @@
724724 * the db will be visible to later tests in the run.
725725 */
726726 public function setupDatabase() {
727 - global $wgDBprefix, $wgDBtype;
 727+ global $wgDBprefix;
728728
729729 if ( $this->databaseSetupDone ) {
730730 return;
731731 }
732732
733 - if ( $wgDBprefix === 'parsertest_' || ( $wgDBtype == 'oracle' && $wgDBprefix === 'pt_' ) ) {
 733+ $db = wfGetDB( DB_MASTER );
 734+ $dbType = $db->getType();
 735+
 736+ if ( $wgDBprefix === 'parsertest_' || ( $dbType == 'oracle' && $wgDBprefix === 'pt_' ) ) {
734737 throw new MWException( 'setupDatabase should be called before setupGlobals' );
735738 }
736739
@@ -745,9 +748,7 @@
746749 $this->useTemporaryTables = false;
747750 }
748751
749 - $temporary = $this->useTemporaryTables || $wgDBtype == 'postgres';
750 -
751 - $db = wfGetDB( DB_MASTER );
 752+ $temporary = $this->useTemporaryTables || $dbType == 'postgres';
752753 $tables = $this->listTables();
753754
754755 foreach ( $tables as $tbl ) {
@@ -756,12 +757,12 @@
757758 # fix back and forth so tableName() works right.
758759 $this->changePrefix( $this->oldTablePrefix );
759760 $oldTableName = $db->tableName( $tbl );
760 - $this->changePrefix( $wgDBtype != 'oracle' ? 'parsertest_' : 'pt_' );
 761+ $this->changePrefix( $dbType != 'oracle' ? 'parsertest_' : 'pt_' );
761762 $newTableName = $db->tableName( $tbl );
762763
763 - if ( $wgDBtype == 'mysql' ) {
 764+ if ( $dbType == 'mysql' ) {
764765 $db->query( "DROP TABLE IF EXISTS $newTableName" );
765 - } elseif ( in_array( $wgDBtype, array( 'postgres', 'oracle' ) ) ) {
 766+ } elseif ( in_array( $dbType, array( 'postgres', 'oracle' ) ) ) {
766767 /* DROPs wouldn't work due to Foreign Key Constraints (bug 14990, r58669)
767768 * Use "DROP TABLE IF EXISTS $newTableName CASCADE" for postgres? That
768769 * syntax would also work for mysql.
@@ -774,12 +775,12 @@
775776 $db->duplicateTableStructure( $oldTableName, $newTableName, $temporary );
776777 }
777778
778 - if ( $wgDBtype == 'oracle' )
 779+ if ( $dbType == 'oracle' )
779780 $db->query( 'BEGIN FILL_WIKI_INFO; END;' );
780781
781 - $this->changePrefix( $wgDBtype != 'oracle' ? 'parsertest_' : 'pt_' );
 782+ $this->changePrefix( $dbType != 'oracle' ? 'parsertest_' : 'pt_' );
782783
783 - if ( $wgDBtype == 'oracle' ) {
 784+ if ( $dbType == 'oracle' ) {
784785 # Insert 0 user to prevent FK violations
785786
786787 # Anonymous user
@@ -882,8 +883,6 @@
883884 }
884885
885886 public function teardownDatabase() {
886 - global $wgDBtype;
887 -
888887 if ( !$this->databaseSetupDone ) {
889888 $this->teardownGlobals();
890889 return;
@@ -903,11 +902,11 @@
904903 $db = wfGetDB( DB_MASTER );
905904
906905 foreach ( $tables as $table ) {
907 - $sql = $wgDBtype == 'oracle' ? "DROP TABLE pt_$table DROP CONSTRAINTS" : "DROP TABLE `parsertest_$table`";
 906+ $sql = $db->getType() == 'oracle' ? "DROP TABLE pt_$table DROP CONSTRAINTS" : "DROP TABLE `parsertest_$table`";
908907 $db->query( $sql );
909908 }
910909
911 - if ( $wgDBtype == 'oracle' )
 910+ if ( $db->getType() == 'oracle' )
912911 $db->query( 'BEGIN FILL_WIKI_INFO; END;' );
913912
914913 $this->teardownGlobals();
Index: trunk/phase3/maintenance/rebuildall.php
@@ -30,9 +30,8 @@
3131 }
3232
3333 public function execute() {
34 - global $wgDBtype;
3534 // Rebuild the text index
36 - if ( $wgDBtype != 'postgres' ) {
 35+ if ( wfGetDB( DB_SLAVE )->getType() != 'postgres' ) {
3736 $this->output( "** Rebuilding fulltext search index (if you abort this will break searching; run this script again to fix):\n" );
3837 $rebuildText = $this->runChild( 'RebuildTextIndex', 'rebuildtextindex.php' );
3938 $rebuildText->execute();
Index: trunk/phase3/maintenance/upgrade1_5.php
@@ -125,12 +125,10 @@
126126 * @access private
127127 */
128128 function streamConnection() {
129 - global $wgDBtype;
130 -
131129 $timeout = 3600 * 24;
132130 $db = $this->newConnection();
133131 $db->bufferResults( false );
134 - if ( $wgDBtype == 'mysql' ) {
 132+ if ( $db->getType() == 'mysql' ) {
135133 $db->query( "SET net_read_timeout=$timeout" );
136134 $db->query( "SET net_write_timeout=$timeout" );
137135 }
Index: trunk/phase3/maintenance/rebuildtextindex.php
@@ -40,10 +40,11 @@
4141 }
4242
4343 public function execute() {
44 - global $wgTitle, $wgDBtype;
 44+ global $wgTitle;
4545
4646 // Shouldn't be needed for Postgres
47 - if ( $wgDBtype == 'postgres' ) {
 47+ $this->db = wfGetDB( DB_MASTER );
 48+ if ( $this->db->getType() == 'postgres' ) {
4849 $this->error( "This script is not needed when using Postgres.\n", true );
4950 }
5051
Index: trunk/phase3/maintenance/sqlite.php
@@ -41,20 +41,18 @@
4242 }
4343
4444 public function execute() {
45 - global $wgDBtype;
46 -
4745 // Should work even if we use a non-SQLite database
4846 if ( $this->hasOption( 'check-syntax' ) ) {
4947 $this->checkSyntax();
5048 }
5149
52 - if ( $wgDBtype != 'sqlite' ) {
 50+ $this->db = wfGetDB( DB_MASTER );
 51+
 52+ if ( $this->db->getType() != 'sqlite' ) {
5353 $this->error( "This maintenance script requires a SQLite database.\n" );
5454 return;
5555 }
5656
57 - $this->db = wfGetDB( DB_MASTER );
58 -
5957 if ( $this->hasOption( 'vacuum' ) ) {
6058 $this->vacuum();
6159 }

Sign-offs

UserFlagDate
Hasharinspected11:26, 27 March 2011

Status & tagging log