From 1993c832779ff758bd005b6a6e24723dce9822ce Mon Sep 17 00:00:00 2001 From: X! Date: Thu, 30 Dec 2010 17:30:35 +0000 Subject: [PATCH] -Destroy the DB automatically when initting the DB -Add $force option to wfSetVar -More work on getting SQLite to work --- includes/GlobalFunctions.php | 5 +++-- includes/db/CloneDatabase.php | 6 ++++++ includes/db/Database.php | 2 +- includes/db/DatabaseSqlite.php | 7 +++++-- tests/phpunit/MediaWikiTestCase.php | 27 ++++++++++++++++++--------- 5 files changed, 33 insertions(+), 14 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 04b0e6b9f3..cf0c4b60af 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -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; diff --git a/includes/db/CloneDatabase.php b/includes/db/CloneDatabase.php index ae47e76c41..6ca06938ba 100644 --- a/includes/db/CloneDatabase.php +++ b/includes/db/CloneDatabase.php @@ -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 ); + } } diff --git a/includes/db/Database.php b/includes/db/Database.php index 1ab7f51746..e8b7c6002b 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -288,7 +288,7 @@ abstract class DatabaseBase implements DatabaseType { } function tablePrefix( $prefix = null ) { - return wfSetVar( $this->mTablePrefix, $prefix ); + return wfSetVar( $this->mTablePrefix, $prefix, true ); } /** diff --git a/includes/db/DatabaseSqlite.php b/includes/db/DatabaseSqlite.php index 242024873a..92b8124fc4 100644 --- a/includes/db/DatabaseSqlite.php +++ b/includes/db/DatabaseSqlite.php @@ -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; + } + } } diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index 71b8d2a6a0..8653353874 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -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' ) ); } } -- 2.20.1