Index: trunk/phase3/tests/parser/parserTest.inc |
— | — | @@ -54,6 +54,12 @@ |
55 | 55 | private $db; |
56 | 56 | |
57 | 57 | /** |
| 58 | + * Database clone helper |
| 59 | + * @var CloneDatabase |
| 60 | + */ |
| 61 | + private $dbClone; |
| 62 | + |
| 63 | + /** |
58 | 64 | * string $oldTablePrefix Original table prefix |
59 | 65 | */ |
60 | 66 | private $oldTablePrefix; |
— | — | @@ -852,7 +858,7 @@ |
853 | 859 | } |
854 | 860 | $this->teardownUploadDir( $this->uploadDir ); |
855 | 861 | |
856 | | - $this->db->tablePrefix( $this->oldTablePrefix ); |
| 862 | + $this->dbClone->destroy(); |
857 | 863 | $this->databaseSetupDone = false; |
858 | 864 | |
859 | 865 | if ( $this->useTemporaryTables ) { |
Index: trunk/phase3/includes/db/DatabaseMysql.php |
— | — | @@ -531,6 +531,13 @@ |
532 | 532 | $this->query( $query, $fname ); |
533 | 533 | } |
534 | 534 | |
| 535 | + public function dropTable( $tableName, $fName = 'DatabaseMysql::dropTable' ) { |
| 536 | + if( !$this->tableExists( $tableName ) ) { |
| 537 | + return false; |
| 538 | + } |
| 539 | + return $this->query( "DROP TABLE IF EXISTS " . $this->tableName( $tableName ), $fName ); |
| 540 | + } |
| 541 | + |
535 | 542 | } |
536 | 543 | |
537 | 544 | /** |
Index: trunk/phase3/includes/db/Database.php |
— | — | @@ -2640,6 +2640,20 @@ |
2641 | 2641 | } |
2642 | 2642 | |
2643 | 2643 | /** |
| 2644 | + * Delete a table |
| 2645 | + */ |
| 2646 | + public function dropTable( $tableName, $method = 'DatabaseBase::dropTable' ) { |
| 2647 | + if( !$this->tableExists( $tableName, $method ) ) { |
| 2648 | + return false; |
| 2649 | + } |
| 2650 | + $sql = "DROP TABLE " . $this->tableName( $tableName ); |
| 2651 | + if( $this->cascadingDeletes() ) { |
| 2652 | + $sql .= " CASCADE"; |
| 2653 | + } |
| 2654 | + return $this->query( $sql ); |
| 2655 | + } |
| 2656 | + |
| 2657 | + /** |
2644 | 2658 | * Get search engine class. All subclasses of this need to implement this |
2645 | 2659 | * if they wish to use searching. |
2646 | 2660 | * |
Index: trunk/phase3/includes/db/CloneDatabase.php |
— | — | @@ -95,16 +95,7 @@ |
96 | 96 | $newTableName = $this->db->tableName( $tbl ); |
97 | 97 | |
98 | 98 | if( $this->dropCurrentTables ) { |
99 | | - if ( $this->db->getType() == 'mysql' && $this->db->tableExists( $tbl ) ) { |
100 | | - $this->db->query( "DROP TABLE IF EXISTS $newTableName" ); |
101 | | - } elseif ( in_array( $this->db->getType(), array( 'postgres', 'oracle' ) ) ) { |
102 | | - /* DROPs wouldn't work due to Foreign Key Constraints (bug 14990, r58669) |
103 | | - * Use "DROP TABLE IF EXISTS $newTableName CASCADE" for postgres? That |
104 | | - * syntax would also work for mysql. |
105 | | - */ |
106 | | - } elseif ( $this->db->tableExists( $tbl ) ) { |
107 | | - $this->db->query( "DROP TABLE $newTableName" ); |
108 | | - } |
| 99 | + $this->db->dropTable( $newTableName, __METHOD__ ); |
109 | 100 | } |
110 | 101 | |
111 | 102 | # Create new table |
— | — | @@ -113,6 +104,20 @@ |
114 | 105 | } |
115 | 106 | |
116 | 107 | /** |
| 108 | + * Change the prefix back to the original. |
| 109 | + * @param $dropTables bool Optionally drop the tables we created |
| 110 | + */ |
| 111 | + public function destroy( $dropTables = false ) { |
| 112 | + if( $dropTables ) { |
| 113 | + $this->changePrefix( $this->newTablePrefix ); |
| 114 | + foreach( $this->tablesToClone as $tbl ) { |
| 115 | + $this->db->dropTable( $tbl ); |
| 116 | + } |
| 117 | + } |
| 118 | + $this->changePrefix( $this->oldTablePrefix ); |
| 119 | + } |
| 120 | + |
| 121 | + /** |
117 | 122 | * Change the table prefix on all open DB connections/ |
118 | 123 | */ |
119 | 124 | protected function changePrefix( $prefix ) { |