Index: trunk/phase3/tests/phpunit/MediaWikiTestCase.php |
— | — | @@ -11,6 +11,7 @@ |
12 | 12 | protected $db; |
13 | 13 | protected $oldTablePrefix; |
14 | 14 | protected $useTemporaryTables = true; |
| 15 | + protected $reuseDB = false; |
15 | 16 | private static $dbSetup = false; |
16 | 17 | |
17 | 18 | /** |
— | — | @@ -41,8 +42,10 @@ |
42 | 43 | ObjectCache::$instances[CACHE_DB] = new HashBagOStuff; |
43 | 44 | |
44 | 45 | if( $this->needsDB() ) { |
45 | | - |
46 | 46 | global $wgDBprefix; |
| 47 | + |
| 48 | + $this->useTemporaryTables = !$this->getCliArg( 'use-normal-tables' ); |
| 49 | + $this->reuseDB = $this->getCliArg('reuse-db'); |
47 | 50 | |
48 | 51 | $this->db = wfGetDB( DB_MASTER ); |
49 | 52 | |
— | — | @@ -82,7 +85,31 @@ |
83 | 86 | function addDBData() {} |
84 | 87 | |
85 | 88 | private function addCoreDBData() { |
| 89 | + if ( $this->db->getType() == 'oracle' ) { |
86 | 90 | |
| 91 | + # Insert 0 user to prevent FK violations |
| 92 | + # Anonymous user |
| 93 | + $this->db->insert( 'user', array( |
| 94 | + 'user_id' => 0, |
| 95 | + 'user_name' => 'Anonymous' ), __METHOD__, array( 'IGNORE' ) ); |
| 96 | + |
| 97 | + # Insert 0 page to prevent FK violations |
| 98 | + # Blank page |
| 99 | + $this->db->insert( 'page', array( |
| 100 | + 'page_id' => 0, |
| 101 | + 'page_namespace' => 0, |
| 102 | + 'page_title' => ' ', |
| 103 | + 'page_restrictions' => NULL, |
| 104 | + 'page_counter' => 0, |
| 105 | + 'page_is_redirect' => 0, |
| 106 | + 'page_is_new' => 0, |
| 107 | + 'page_random' => 0, |
| 108 | + 'page_touched' => $this->db->timestamp(), |
| 109 | + 'page_latest' => 0, |
| 110 | + 'page_len' => 0 ), __METHOD__, array( 'IGNORE' ) ); |
| 111 | + |
| 112 | + } |
| 113 | + |
87 | 114 | User::resetIdByNameCache(); |
88 | 115 | |
89 | 116 | //Make sysop user |
— | — | @@ -115,32 +142,17 @@ |
116 | 143 | |
117 | 144 | $dbClone = new CloneDatabase( $this->db, $this->listTables(), $this->dbPrefix() ); |
118 | 145 | $dbClone->useTemporaryTables( $this->useTemporaryTables ); |
119 | | - $dbClone->cloneTableStructure(); |
120 | 146 | |
| 147 | + if ( ( $this->db->getType() == 'oracle' || !$this->useTemporaryTables ) && $this->reuseDB ) { |
| 148 | + CloneDatabase::changePrefix( $this->dbPrefix() ); |
| 149 | + $this->resetDB(); |
| 150 | + return; |
| 151 | + } else { |
| 152 | + $dbClone->cloneTableStructure(); |
| 153 | + } |
| 154 | + |
121 | 155 | if ( $this->db->getType() == 'oracle' ) { |
122 | 156 | $this->db->query( 'BEGIN FILL_WIKI_INFO; END;' ); |
123 | | - |
124 | | - # Insert 0 user to prevent FK violations |
125 | | - # Anonymous user |
126 | | - $this->db->insert( 'user', array( |
127 | | - 'user_id' => 0, |
128 | | - 'user_name' => 'Anonymous' ) ); |
129 | | - |
130 | | - # Insert 0 page to prevent FK violations |
131 | | - # Blank page |
132 | | - $this->db->insert( 'page', array( |
133 | | - 'page_id' => 0, |
134 | | - 'page_namespace' => 0, |
135 | | - 'page_title' => ' ', |
136 | | - 'page_restrictions' => NULL, |
137 | | - 'page_counter' => 0, |
138 | | - 'page_is_redirect' => 0, |
139 | | - 'page_is_new' => 0, |
140 | | - 'page_random' => 0, |
141 | | - 'page_touched' => $this->db->timestamp(), |
142 | | - 'page_latest' => 0, |
143 | | - 'page_len' => 0 ) ); |
144 | | - |
145 | 157 | } |
146 | 158 | } |
147 | 159 | |
— | — | @@ -149,35 +161,29 @@ |
150 | 162 | */ |
151 | 163 | private function resetDB() { |
152 | 164 | if( $this->db ) { |
153 | | - foreach( $this->listTables() as $tbl ) { |
154 | | - if( $tbl == 'interwiki' || $tbl == 'user' || $tbl == 'MWUSER' ) continue; |
155 | | - if ( $this->db->getType() == 'oracle' ) |
156 | | - $this->db->query( 'TRUNCATE TABLE '.$this->db->tableName($tbl), __METHOD__ ); |
157 | | - else |
158 | | - $this->db->delete( $tbl, '*', __METHOD__ ); |
| 165 | + if ( $this->db->getType() == 'oracle' ) { |
| 166 | + if ( $this->useTemporaryTables ) { |
| 167 | + wfGetLB()->closeAll(); |
| 168 | + $this->db = wfGetDB( DB_MASTER ); |
| 169 | + } else { |
| 170 | + foreach( $this->listTables() as $tbl ) { |
| 171 | + if( $tbl == 'interwiki') continue; |
| 172 | + $this->db->query( 'TRUNCATE TABLE '.$this->db->tableName($tbl), __METHOD__ ); |
| 173 | + } |
| 174 | + } |
| 175 | + } else { |
| 176 | + foreach( $this->listTables() as $tbl ) { |
| 177 | + if( $tbl == 'interwiki' || $tbl == 'user' ) continue; |
| 178 | + $this->db->delete( $tbl, '*', __METHOD__ ); |
| 179 | + } |
159 | 180 | } |
160 | | - |
161 | | - if ( $this->db->getType() == 'oracle' ) { |
162 | | - # Insert 0 page to prevent FK violations |
163 | | - # Blank page |
164 | | - $this->db->insert( 'page', array( |
165 | | - 'page_id' => 0, |
166 | | - 'page_namespace' => 0, |
167 | | - 'page_title' => ' ', |
168 | | - 'page_restrictions' => NULL, |
169 | | - 'page_counter' => 0, |
170 | | - 'page_is_redirect' => 0, |
171 | | - 'page_is_new' => 0, |
172 | | - 'page_random' => 0, |
173 | | - 'page_touched' => $this->db->timestamp(), |
174 | | - 'page_latest' => 0, |
175 | | - 'page_len' => 0 ) ); |
176 | | - } |
177 | 181 | } |
178 | 182 | } |
179 | 183 | |
180 | 184 | protected function destroyDB() { |
181 | | - if ( $this->useTemporaryTables || is_null( $this->db ) ) { |
| 185 | + if ( is_null( $this->db ) || |
| 186 | + ( $this->useTemporaryTables && $this->db->getType() != 'oracle' ) || |
| 187 | + ( $this->reuseDB ) ) { |
182 | 188 | # Don't need to do anything |
183 | 189 | return; |
184 | 190 | } |
Index: trunk/phase3/tests/phpunit/MediaWikiPHPUnitCommand.php |
— | — | @@ -6,6 +6,8 @@ |
7 | 7 | 'regex=' => false, |
8 | 8 | 'file=' => false, |
9 | 9 | 'keep-uploads' => false, |
| 10 | + 'use-normal-tables' => false, |
| 11 | + 'reuse-db' => false, |
10 | 12 | ); |
11 | 13 | |
12 | 14 | public function __construct() { |
— | — | @@ -62,6 +64,11 @@ |
63 | 65 | --keep-uploads Re-use the same upload directory for each test, don't delete it |
64 | 66 | |
65 | 67 | |
| 68 | +Database options: |
| 69 | + --use-normal-tables Use normal DB tables. |
| 70 | + --reuse-db Init DB only if tables are missing and keep after finish. |
| 71 | + |
| 72 | + |
66 | 73 | EOT; |
67 | 74 | } |
68 | 75 | |
Index: trunk/phase3/includes/db/DatabaseOracle.php |
— | — | @@ -746,7 +746,7 @@ |
747 | 747 | } |
748 | 748 | |
749 | 749 | function duplicateTableStructure( $oldName, $newName, $temporary = false, $fname = 'DatabaseOracle::duplicateTableStructure' ) { |
750 | | - $temporary = 'FALSE'; //$temporary ? 'TRUE' : 'FALSE'; |
| 750 | + $temporary = $temporary ? 'TRUE' : 'FALSE'; |
751 | 751 | |
752 | 752 | $newName = strtoupper( $newName ); |
753 | 753 | $oldName = strtoupper( $oldName ); |
Index: trunk/phase3/includes/db/CloneDatabase.php |
— | — | @@ -98,7 +98,7 @@ |
99 | 99 | self::changePrefix( $this->newTablePrefix ); |
100 | 100 | $newTableName = $this->db->tableName( $tbl, 'raw' ); |
101 | 101 | |
102 | | - if( $this->dropCurrentTables && !in_array( $this->db->getType(), array( 'postgres' ) ) ) { |
| 102 | + if( $this->dropCurrentTables && !in_array( $this->db->getType(), array( 'postgres', 'oracle' ) ) ) { |
103 | 103 | $this->db->dropTable( $tbl, __METHOD__ ); |
104 | 104 | wfDebug( __METHOD__." dropping {$newTableName}\n", true); |
105 | 105 | //Dropping the oldTable because the prefix was changed |