-Destroy the DB automatically when initting the DB
authorX! <soxred93@users.mediawiki.org>
Thu, 30 Dec 2010 17:30:35 +0000 (17:30 +0000)
committerX! <soxred93@users.mediawiki.org>
Thu, 30 Dec 2010 17:30:35 +0000 (17:30 +0000)
-Add $force option to wfSetVar
-More work on getting SQLite to work

includes/GlobalFunctions.php
includes/db/CloneDatabase.php
includes/db/Database.php
includes/db/DatabaseSqlite.php
tests/phpunit/MediaWikiTestCase.php

index 04b0e6b..cf0c4b6 100644 (file)
@@ -1287,10 +1287,11 @@ function wfTime() {
 /**
  * Sets dest to source and returns the original value of dest
  * If source is NULL, it just returns the value, it doesn't set the variable
+ * If force is true, it will set the value even if source is NULL
  */
-function wfSetVar( &$dest, $source ) {
+function wfSetVar( &$dest, $source, $force = false ) {
        $temp = $dest;
-       if ( !is_null( $source ) ) {
+       if ( !is_null( $source ) || $force ) {
                $dest = $source;
        }
        return $temp;
index ae47e76..6ca0693 100644 (file)
@@ -85,12 +85,16 @@ class CloneDatabase {
         * Clone the table structure
         */
        public function cloneTableStructure() {
+       
+               sort($this->tablesToClone);
+               
                foreach( $this->tablesToClone as $tbl ) {
                        # Clean up from previous aborted run.  So that table escaping
                        # works correctly across DB engines, we need to change the pre-
                        # fix back and forth so tableName() works right.
                        $this->changePrefix( $this->oldTablePrefix );
                        $oldTableName = $this->db->tableName( $tbl );
+                       
                        $this->changePrefix( $this->newTablePrefix );
                        $newTableName = $this->db->tableName( $tbl );
 
@@ -99,7 +103,9 @@ class CloneDatabase {
                        }
 
                        # Create new table
+                       wfDebug( "Duplicating $oldTableName to $newTableName\n", __METHOD__ );
                        $this->db->duplicateTableStructure( $oldTableName, $newTableName, $this->useTemporaryTables );
+                       
                }
        }
 
index 1ab7f51..e8b7c60 100644 (file)
@@ -288,7 +288,7 @@ abstract class DatabaseBase implements DatabaseType {
        }
 
        function tablePrefix( $prefix = null ) {
-               return wfSetVar( $this->mTablePrefix, $prefix );
+               return wfSetVar( $this->mTablePrefix, $prefix, true );
        }
 
        /**
index 2420248..92b8124 100644 (file)
@@ -629,8 +629,11 @@ class DatabaseSqlite extends DatabaseBase {
                        $vars = get_object_vars($table);
                        $table = array_pop( $vars );
                        
-                       if( empty( $prefix ) || strpos( $table, $prefix ) === 0 ) {
-                               $endArray[] = $table;
+                       if( !$prefix || strpos( $table, $prefix ) === 0 ) {
+                               if ( strpos( $table, 'sqlite_' ) !== 0 ) {
+                                       $endArray[] = $table;
+                               }
+                               
                        }
                }
                
index 71b8d2a..8653353 100644 (file)
@@ -12,24 +12,33 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
        protected $useTemporaryTables = true;
 
        function  __construct( $name = null, array $data = array(), $dataName = '' ) {
-        if ($name !== null) {
-            $this->setName($name);
-        }
+               if ($name !== null) {
+                       $this->setName($name);
+               }
 
-        $this->data = $data;
-        $this->dataName = $dataName;
+               $this->data = $data;
+               $this->dataName = $dataName;
        }
        
        function run( PHPUnit_Framework_TestResult $result = NULL ) {
-               if( $this->needsDB() && !is_object( $this->dbClone ) ) {
+               
+               if( $this->needsDB() ) {
+                       
+                       $this->destroyDBCheck();
+                       
                        $this->initDB();
                        $this->addCoreDBData();
                        $this->addDBData();
                }
+               
                parent::run( $result );
        }
-
+       
        function __destruct() {
+               $this->destroyDBCheck();
+       }
+
+       function destroyDBCheck() {
                if( is_object( $this->dbClone ) && $this->dbClone instanceof CloneDatabase ) {
                        $this->destroyDB();
                }
@@ -110,8 +119,8 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                        
                        # Anonymous user
                        $this->db->insert( 'user', array(
-                               'user_id'         => 0,
-                               'user_name'       => 'Anonymous' ) );
+                               'user_id'               => 0,
+                               'user_name'     => 'Anonymous' ) );
                }
                
        }