$newTableName = $this->db->tableName( $tbl );
if( $this->dropCurrentTables ) {
- if ( $this->db->getType() == 'mysql' && $this->db->tableExists( $tbl ) ) {
- $this->db->query( "DROP TABLE IF EXISTS $newTableName" );
- } elseif ( in_array( $this->db->getType(), array( 'postgres', 'oracle' ) ) ) {
- /* DROPs wouldn't work due to Foreign Key Constraints (bug 14990, r58669)
- * Use "DROP TABLE IF EXISTS $newTableName CASCADE" for postgres? That
- * syntax would also work for mysql.
- */
- } elseif ( $this->db->tableExists( $tbl ) ) {
- $this->db->query( "DROP TABLE $newTableName" );
- }
+ $this->db->dropTable( $newTableName, __METHOD__ );
}
# Create new table
}
}
+ /**
+ * Change the prefix back to the original.
+ * @param $dropTables bool Optionally drop the tables we created
+ */
+ public function destroy( $dropTables = false ) {
+ if( $dropTables ) {
+ $this->changePrefix( $this->newTablePrefix );
+ foreach( $this->tablesToClone as $tbl ) {
+ $this->db->dropTable( $tbl );
+ }
+ }
+ $this->changePrefix( $this->oldTablePrefix );
+ }
+
/**
* Change the table prefix on all open DB connections/
*/
return true;
}
+ /**
+ * Delete a table
+ */
+ public function dropTable( $tableName, $method = 'DatabaseBase::dropTable' ) {
+ if( !$this->tableExists( $tableName, $method ) ) {
+ return false;
+ }
+ $sql = "DROP TABLE " . $this->tableName( $tableName );
+ if( $this->cascadingDeletes() ) {
+ $sql .= " CASCADE";
+ }
+ return $this->query( $sql );
+ }
+
/**
* Get search engine class. All subclasses of this need to implement this
* if they wish to use searching.
$this->query( $query, $fname );
}
+ public function dropTable( $tableName, $fName = 'DatabaseMysql::dropTable' ) {
+ if( !$this->tableExists( $tableName ) ) {
+ return false;
+ }
+ return $this->query( "DROP TABLE IF EXISTS " . $this->tableName( $tableName ), $fName );
+ }
+
}
/**
*/
private $db;
+ /**
+ * Database clone helper
+ * @var CloneDatabase
+ */
+ private $dbClone;
+
/**
* string $oldTablePrefix Original table prefix
*/
}
$this->teardownUploadDir( $this->uploadDir );
- $this->db->tablePrefix( $this->oldTablePrefix );
+ $this->dbClone->destroy();
$this->databaseSetupDone = false;
if ( $this->useTemporaryTables ) {