r79272 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79271‎ | r79272 | r79273 >
Date:17:30, 30 December 2010
Author:soxred93
Status:resolved (Comments)
Tags:
Comment:
-Destroy the DB automatically when initting the DB
-Add $force option to wfSetVar
-More work on getting SQLite to work
Modified paths:
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/includes/db/CloneDatabase.php (modified) (history)
  • /trunk/phase3/includes/db/Database.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseSqlite.php (modified) (history)
  • /trunk/phase3/tests/phpunit/MediaWikiTestCase.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/MediaWikiTestCase.php
@@ -12,24 +12,33 @@
1313 protected $useTemporaryTables = true;
1414
1515 function __construct( $name = null, array $data = array(), $dataName = '' ) {
16 - if ($name !== null) {
17 - $this->setName($name);
18 - }
 16+ if ($name !== null) {
 17+ $this->setName($name);
 18+ }
1919
20 - $this->data = $data;
21 - $this->dataName = $dataName;
 20+ $this->data = $data;
 21+ $this->dataName = $dataName;
2222 }
2323
2424 function run( PHPUnit_Framework_TestResult $result = NULL ) {
25 - if( $this->needsDB() && !is_object( $this->dbClone ) ) {
 25+
 26+ if( $this->needsDB() ) {
 27+
 28+ $this->destroyDBCheck();
 29+
2630 $this->initDB();
2731 $this->addCoreDBData();
2832 $this->addDBData();
2933 }
 34+
3035 parent::run( $result );
3136 }
 37+
 38+ function __destruct() {
 39+ $this->destroyDBCheck();
 40+ }
3241
33 - function __destruct() {
 42+ function destroyDBCheck() {
3443 if( is_object( $this->dbClone ) && $this->dbClone instanceof CloneDatabase ) {
3544 $this->destroyDB();
3645 }
@@ -110,8 +119,8 @@
111120
112121 # Anonymous user
113122 $this->db->insert( 'user', array(
114 - 'user_id' => 0,
115 - 'user_name' => 'Anonymous' ) );
 123+ 'user_id' => 0,
 124+ 'user_name' => 'Anonymous' ) );
116125 }
117126
118127 }
Index: trunk/phase3/includes/GlobalFunctions.php
@@ -1287,10 +1287,11 @@
12881288 /**
12891289 * Sets dest to source and returns the original value of dest
12901290 * If source is NULL, it just returns the value, it doesn't set the variable
 1291+ * If force is true, it will set the value even if source is NULL
12911292 */
1292 -function wfSetVar( &$dest, $source ) {
 1293+function wfSetVar( &$dest, $source, $force = false ) {
12931294 $temp = $dest;
1294 - if ( !is_null( $source ) ) {
 1295+ if ( !is_null( $source ) || $force ) {
12951296 $dest = $source;
12961297 }
12971298 return $temp;
Index: trunk/phase3/includes/db/Database.php
@@ -288,7 +288,7 @@
289289 }
290290
291291 function tablePrefix( $prefix = null ) {
292 - return wfSetVar( $this->mTablePrefix, $prefix );
 292+ return wfSetVar( $this->mTablePrefix, $prefix, true );
293293 }
294294
295295 /**
Index: trunk/phase3/includes/db/CloneDatabase.php
@@ -85,12 +85,16 @@
8686 * Clone the table structure
8787 */
8888 public function cloneTableStructure() {
 89+
 90+ sort($this->tablesToClone);
 91+
8992 foreach( $this->tablesToClone as $tbl ) {
9093 # Clean up from previous aborted run. So that table escaping
9194 # works correctly across DB engines, we need to change the pre-
9295 # fix back and forth so tableName() works right.
9396 $this->changePrefix( $this->oldTablePrefix );
9497 $oldTableName = $this->db->tableName( $tbl );
 98+
9599 $this->changePrefix( $this->newTablePrefix );
96100 $newTableName = $this->db->tableName( $tbl );
97101
@@ -99,7 +103,9 @@
100104 }
101105
102106 # Create new table
 107+ wfDebug( "Duplicating $oldTableName to $newTableName\n", __METHOD__ );
103108 $this->db->duplicateTableStructure( $oldTableName, $newTableName, $this->useTemporaryTables );
 109+
104110 }
105111 }
106112
Index: trunk/phase3/includes/db/DatabaseSqlite.php
@@ -629,8 +629,11 @@
630630 $vars = get_object_vars($table);
631631 $table = array_pop( $vars );
632632
633 - if( empty( $prefix ) || strpos( $table, $prefix ) === 0 ) {
634 - $endArray[] = $table;
 633+ if( !$prefix || strpos( $table, $prefix ) === 0 ) {
 634+ if ( strpos( $table, 'sqlite_' ) !== 0 ) {
 635+ $endArray[] = $table;
 636+ }
 637+
635638 }
636639 }
637640

Follow-up revisions

RevisionCommit summaryAuthorDate
r84371correct wfDebug() calls added in r79272 & r79368hashar11:39, 20 March 2011
r88755Fixup phpunit tests so we don't drop/create tables on EVERY SINGLE TEST....demon21:22, 24 May 2011
r91526* MFT r88134: Fixed a bug in transformation where previous language could lea...tstarling05:44, 6 July 2011
r92710Revert DatabaseBase::tablePrefix() part of r79272: doesn't seem to be really ...demon23:27, 20 July 2011

Comments

#Comment by Hashar (talk | contribs)   20:45, 17 March 2011

I do not think destroying the DB on every test is a great idea. We could just clean it up and destroy it only for tests that really need an empty DB.

#Comment by Tim Starling (talk | contribs)   05:34, 6 July 2011
 	function tablePrefix( $prefix = null ) {
-		return wfSetVar( $this->mTablePrefix, $prefix );
+		return wfSetVar( $this->mTablePrefix, $prefix, true );
 	}

Doesn't this break anything that tries to use tablePrefix() as an accessor rather than a mutator?

#Comment by Catrope (talk | contribs)   23:11, 20 July 2011

This code is long since superseded per Chad. He says Tim does have a point, and will back the wfSetVar change out if that doesn't break the tests.

Status & tagging log