# works correctly across DB engines, we need to change the pre-
# fix back and forth so tableName() works right.
- $this->changePrefix( $this->oldTablePrefix );
+ self::changePrefix( $this->oldTablePrefix );
$oldTableName = $this->db->tableName( $tbl );
- $this->changePrefix( $this->newTablePrefix );
+ self::changePrefix( $this->newTablePrefix );
$newTableName = $this->db->tableName( $tbl );
if( $this->dropCurrentTables && !in_array( $this->db->getType(), array( 'postgres' ) ) ) {
$this->db->dropTable( $tbl, __METHOD__ );
+ wfDebug( "Dropping {$this->newTablePrefix}{$oldTableName}\n", __METHOD__ );
//Dropping the oldTable because the prefix was changed
}
*/
public function destroy( $dropTables = false ) {
if( $dropTables ) {
- $this->changePrefix( $this->newTablePrefix );
+ self::changePrefix( $this->newTablePrefix );
foreach( $this->tablesToClone as $tbl ) {
$this->db->dropTable( $tbl );
}
}
- $this->changePrefix( $this->oldTablePrefix );
+ self::changePrefix( $this->oldTablePrefix );
}
/**
* @param $prefix
* @return void
*/
- protected function changePrefix( $prefix ) {
+ public static function changePrefix( $prefix ) {
global $wgDBprefix;
- wfGetLBFactory()->forEachLB( array( $this, 'changeLBPrefix' ), array( $prefix ) );
+ wfGetLBFactory()->forEachLB( array( 'CloneDatabase', 'changeLBPrefix' ), array( $prefix ) );
$wgDBprefix = $prefix;
}
* @param $prefix
* @return void
*/
- public function changeLBPrefix( $lb, $prefix ) {
- $lb->forEachOpenConnection( array( $this, 'changeDBPrefix' ), array( $prefix ) );
+ public static function changeLBPrefix( $lb, $prefix ) {
+ $lb->forEachOpenConnection( array( 'CloneDatabase', 'changeDBPrefix' ), array( $prefix ) );
}
/**
* @param $prefix
* @return void
*/
- public function changeDBPrefix( $db, $prefix ) {
+ public static function changeDBPrefix( $db, $prefix ) {
$db->tablePrefix( $prefix );
}
}
public $regex = '';
public $runDisabled = false;
- protected static $databaseSetupDone = false;
protected $db;
protected $dbClone;
protected $oldTablePrefix;
if( $this->needsDB() ) {
- $this->destroyDBCheck();
+ $this->db = wfGetDB( DB_MASTER );
+
+ $this->destroyDB();
$this->initDB();
$this->addCoreDBData();
}
function __destruct() {
- $this->destroyDBCheck();
- }
-
- function destroyDBCheck() {
- if( is_object( $this->dbClone ) && $this->dbClone instanceof CloneDatabase ) {
- $this->destroyDB();
- }
+ $this->destroyDB();
}
function needsDB() {
private function initDB() {
global $wgDBprefix;
- if ( self::$databaseSetupDone ) {
- return;
- }
-
- $this->db = wfGetDB( DB_MASTER );
$dbType = $this->db->getType();
if ( $wgDBprefix === 'unittest_' || ( $dbType == 'oracle' && $wgDBprefix === 'ut_' ) ) {
throw new MWException( 'Cannot run unit tests, the database prefix is already "unittest_"' );
}
- self::$databaseSetupDone = true;
$this->oldTablePrefix = $wgDBprefix;
- # SqlBagOStuff broke when using temporary tables on r40209 (bug 15892).
- # It seems to have been fixed since (r55079?).
- # If it fails, $wgCaches[CACHE_DB] = new HashBagOStuff(); should work around it.
-
- # CREATE TEMPORARY TABLE breaks if there is more than one server
- if ( wfGetLB()->getServerCount() != 1 ) {
- $this->useTemporaryTables = false;
- }
-
- $temporary = $this->useTemporaryTables || $dbType == 'postgres';
-
$tables = $this->listTables();
$prefix = $dbType != 'oracle' ? 'unittest_' : 'ut_';
$this->dbClone = new CloneDatabase( $this->db, $tables, $prefix );
- $this->dbClone->useTemporaryTables( $temporary );
$this->dbClone->cloneTableStructure();
if ( $dbType == 'oracle' )
}
protected function destroyDB() {
- if ( !self::$databaseSetupDone ) {
- return;
- }
+ global $wgDBprefix;
- $this->dbClone->destroy();
- self::$databaseSetupDone = false;
-
if ( $this->useTemporaryTables ) {
# Don't need to do anything
//return;
}
foreach ( $tables as $table ) {
- $sql = $this->db->getType() == 'oracle' ? "DROP TABLE $table DROP CONSTRAINTS" : "DROP TABLE `$table`";
- $this->db->query( $sql );
+ if( $this->db->tableExists( "`$table`" ) ) {
+ $sql = $this->db->getType() == 'oracle' ? "DROP TABLE $table DROP CONSTRAINTS" : "DROP TABLE `$table`";
+ $this->db->query( $sql, __METHOD__ );
+ }
}
-
- if ( $this->db->getType() == 'oracle' )
- $this->db->query( 'BEGIN FILL_WIKI_INFO; END;' );
+ if ( $this->db->getType() == 'oracle' )
+ $this->db->query( 'BEGIN FILL_WIKI_INFO; END;', __METHOD__ );
+ CloneDatabase::changePrefix( $this->oldTablePrefix );
}
function __call( $func, $args ) {