Index: trunk/phase3/tests/phpunit/MediaWikiTestCase.php |
— | — | @@ -5,7 +5,6 @@ |
6 | 6 | public $regex = ''; |
7 | 7 | public $runDisabled = false; |
8 | 8 | |
9 | | - protected static $databaseSetupDone = false; |
10 | 9 | protected $db; |
11 | 10 | protected $dbClone; |
12 | 11 | protected $oldTablePrefix; |
— | — | @@ -24,8 +23,10 @@ |
25 | 24 | |
26 | 25 | if( $this->needsDB() ) { |
27 | 26 | |
28 | | - $this->destroyDBCheck(); |
| 27 | + $this->db = wfGetDB( DB_MASTER ); |
29 | 28 | |
| 29 | + $this->destroyDB(); |
| 30 | + |
30 | 31 | $this->initDB(); |
31 | 32 | $this->addCoreDBData(); |
32 | 33 | $this->addDBData(); |
— | — | @@ -35,14 +36,8 @@ |
36 | 37 | } |
37 | 38 | |
38 | 39 | function __destruct() { |
39 | | - $this->destroyDBCheck(); |
| 40 | + $this->destroyDB(); |
40 | 41 | } |
41 | | - |
42 | | - function destroyDBCheck() { |
43 | | - if( is_object( $this->dbClone ) && $this->dbClone instanceof CloneDatabase ) { |
44 | | - $this->destroyDB(); |
45 | | - } |
46 | | - } |
47 | 42 | |
48 | 43 | function needsDB() { |
49 | 44 | $rc = new ReflectionClass( $this ); |
— | — | @@ -78,37 +73,19 @@ |
79 | 74 | private function initDB() { |
80 | 75 | global $wgDBprefix; |
81 | 76 | |
82 | | - if ( self::$databaseSetupDone ) { |
83 | | - return; |
84 | | - } |
85 | | - |
86 | | - $this->db = wfGetDB( DB_MASTER ); |
87 | 77 | $dbType = $this->db->getType(); |
88 | 78 | |
89 | 79 | if ( $wgDBprefix === 'unittest_' || ( $dbType == 'oracle' && $wgDBprefix === 'ut_' ) ) { |
90 | 80 | throw new MWException( 'Cannot run unit tests, the database prefix is already "unittest_"' ); |
91 | 81 | } |
92 | 82 | |
93 | | - self::$databaseSetupDone = true; |
94 | 83 | $this->oldTablePrefix = $wgDBprefix; |
95 | 84 | |
96 | | - # SqlBagOStuff broke when using temporary tables on r40209 (bug 15892). |
97 | | - # It seems to have been fixed since (r55079?). |
98 | | - # If it fails, $wgCaches[CACHE_DB] = new HashBagOStuff(); should work around it. |
99 | | - |
100 | | - # CREATE TEMPORARY TABLE breaks if there is more than one server |
101 | | - if ( wfGetLB()->getServerCount() != 1 ) { |
102 | | - $this->useTemporaryTables = false; |
103 | | - } |
104 | | - |
105 | | - $temporary = $this->useTemporaryTables || $dbType == 'postgres'; |
106 | | - |
107 | 85 | $tables = $this->listTables(); |
108 | 86 | |
109 | 87 | $prefix = $dbType != 'oracle' ? 'unittest_' : 'ut_'; |
110 | 88 | |
111 | 89 | $this->dbClone = new CloneDatabase( $this->db, $tables, $prefix ); |
112 | | - $this->dbClone->useTemporaryTables( $temporary ); |
113 | 90 | $this->dbClone->cloneTableStructure(); |
114 | 91 | |
115 | 92 | if ( $dbType == 'oracle' ) |
— | — | @@ -126,13 +103,8 @@ |
127 | 104 | } |
128 | 105 | |
129 | 106 | protected function destroyDB() { |
130 | | - if ( !self::$databaseSetupDone ) { |
131 | | - return; |
132 | | - } |
| 107 | + global $wgDBprefix; |
133 | 108 | |
134 | | - $this->dbClone->destroy(); |
135 | | - self::$databaseSetupDone = false; |
136 | | - |
137 | 109 | if ( $this->useTemporaryTables ) { |
138 | 110 | # Don't need to do anything |
139 | 111 | //return; |
— | — | @@ -147,14 +119,16 @@ |
148 | 120 | } |
149 | 121 | |
150 | 122 | foreach ( $tables as $table ) { |
151 | | - $sql = $this->db->getType() == 'oracle' ? "DROP TABLE $table DROP CONSTRAINTS" : "DROP TABLE `$table`"; |
152 | | - $this->db->query( $sql ); |
| 123 | + if( $this->db->tableExists( "`$table`" ) ) { |
| 124 | + $sql = $this->db->getType() == 'oracle' ? "DROP TABLE $table DROP CONSTRAINTS" : "DROP TABLE `$table`"; |
| 125 | + $this->db->query( $sql, __METHOD__ ); |
| 126 | + } |
153 | 127 | } |
154 | | - |
| 128 | + |
155 | 129 | if ( $this->db->getType() == 'oracle' ) |
156 | | - $this->db->query( 'BEGIN FILL_WIKI_INFO; END;' ); |
| 130 | + $this->db->query( 'BEGIN FILL_WIKI_INFO; END;', __METHOD__ ); |
157 | 131 | |
158 | | - |
| 132 | + CloneDatabase::changePrefix( $this->oldTablePrefix ); |
159 | 133 | } |
160 | 134 | |
161 | 135 | function __call( $func, $args ) { |
Index: trunk/phase3/includes/db/CloneDatabase.php |
— | — | @@ -91,14 +91,15 @@ |
92 | 92 | # works correctly across DB engines, we need to change the pre- |
93 | 93 | # fix back and forth so tableName() works right. |
94 | 94 | |
95 | | - $this->changePrefix( $this->oldTablePrefix ); |
| 95 | + self::changePrefix( $this->oldTablePrefix ); |
96 | 96 | $oldTableName = $this->db->tableName( $tbl ); |
97 | 97 | |
98 | | - $this->changePrefix( $this->newTablePrefix ); |
| 98 | + self::changePrefix( $this->newTablePrefix ); |
99 | 99 | $newTableName = $this->db->tableName( $tbl ); |
100 | 100 | |
101 | 101 | if( $this->dropCurrentTables && !in_array( $this->db->getType(), array( 'postgres' ) ) ) { |
102 | 102 | $this->db->dropTable( $tbl, __METHOD__ ); |
| 103 | + wfDebug( "Dropping {$this->newTablePrefix}{$oldTableName}\n", __METHOD__ ); |
103 | 104 | //Dropping the oldTable because the prefix was changed |
104 | 105 | } |
105 | 106 | |
— | — | @@ -116,12 +117,12 @@ |
117 | 118 | */ |
118 | 119 | public function destroy( $dropTables = false ) { |
119 | 120 | if( $dropTables ) { |
120 | | - $this->changePrefix( $this->newTablePrefix ); |
| 121 | + self::changePrefix( $this->newTablePrefix ); |
121 | 122 | foreach( $this->tablesToClone as $tbl ) { |
122 | 123 | $this->db->dropTable( $tbl ); |
123 | 124 | } |
124 | 125 | } |
125 | | - $this->changePrefix( $this->oldTablePrefix ); |
| 126 | + self::changePrefix( $this->oldTablePrefix ); |
126 | 127 | } |
127 | 128 | |
128 | 129 | /** |
— | — | @@ -130,9 +131,9 @@ |
131 | 132 | * @param $prefix |
132 | 133 | * @return void |
133 | 134 | */ |
134 | | - protected function changePrefix( $prefix ) { |
| 135 | + public static function changePrefix( $prefix ) { |
135 | 136 | global $wgDBprefix; |
136 | | - wfGetLBFactory()->forEachLB( array( $this, 'changeLBPrefix' ), array( $prefix ) ); |
| 137 | + wfGetLBFactory()->forEachLB( array( 'CloneDatabase', 'changeLBPrefix' ), array( $prefix ) ); |
137 | 138 | $wgDBprefix = $prefix; |
138 | 139 | } |
139 | 140 | |
— | — | @@ -141,8 +142,8 @@ |
142 | 143 | * @param $prefix |
143 | 144 | * @return void |
144 | 145 | */ |
145 | | - public function changeLBPrefix( $lb, $prefix ) { |
146 | | - $lb->forEachOpenConnection( array( $this, 'changeDBPrefix' ), array( $prefix ) ); |
| 146 | + public static function changeLBPrefix( $lb, $prefix ) { |
| 147 | + $lb->forEachOpenConnection( array( 'CloneDatabase', 'changeDBPrefix' ), array( $prefix ) ); |
147 | 148 | } |
148 | 149 | |
149 | 150 | /** |
— | — | @@ -150,7 +151,7 @@ |
151 | 152 | * @param $prefix |
152 | 153 | * @return void |
153 | 154 | */ |
154 | | - public function changeDBPrefix( $db, $prefix ) { |
| 155 | + public static function changeDBPrefix( $db, $prefix ) { |
155 | 156 | $db->tablePrefix( $prefix ); |
156 | 157 | } |
157 | 158 | } |
Index: trunk/phase3/includes/db/DatabaseSqlite.php |
— | — | @@ -595,6 +595,7 @@ |
596 | 596 | } |
597 | 597 | |
598 | 598 | function duplicateTableStructure( $oldName, $newName, $temporary = false, $fname = 'DatabaseSqlite::duplicateTableStructure' ) { |
| 599 | + |
599 | 600 | $res = $this->query( "SELECT sql FROM sqlite_master WHERE tbl_name='$oldName' AND type='table'", $fname ); |
600 | 601 | $obj = $this->fetchObject( $res ); |
601 | 602 | if ( !$obj ) { |