Index: branches/new-installer/phase3/includes/db/SchemaBuilder.php |
— | — | @@ -18,7 +18,6 @@ |
19 | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
20 | 20 | * |
21 | 21 | * @author Chad Horohoe <chad@anyonecanedit.org> |
22 | | - * @todo Handle custom table options, eg: MyISAM for searchindex, MAX_ROWS, etc |
23 | 22 | * @todo Handle lengths on indexes, eg: el_from, el_to(40) |
24 | 23 | * @toto Handle REFERENCES/ON DELETE CASCADE |
25 | 24 | */ |
— | — | @@ -35,17 +34,28 @@ |
36 | 35 | // Any options for the table creation. Things like ENGINE=InnoDB |
37 | 36 | protected $tblOptions = array(); |
38 | 37 | |
| 38 | + /** |
| 39 | + * Pieces accessible to extensions |
| 40 | + */ |
| 41 | + |
39 | 42 | // Our table definition |
40 | | - protected $tables = array(); |
| 43 | + public $tables = array(); |
41 | 44 | |
| 45 | + // Old tables that should be deleted if they're still present |
| 46 | + public $tablesToDelete = array(); |
| 47 | + |
42 | 48 | /** |
| 49 | + * End externally-visible fields |
| 50 | + */ |
| 51 | + |
| 52 | + /** |
43 | 53 | * Constructor. We hide it so people don't try to construct their own schema |
44 | 54 | * classes. Use a sane entry point, like newFromType() |
45 | 55 | * |
46 | 56 | * @param $schema Array See Schema::$defaultTables for more information |
47 | 57 | */ |
48 | 58 | private final function __construct( $schema ) { |
49 | | - wfRunHooks( 'LoadExtensionSchemaUpdates', array( &$schema ) ); |
| 59 | + wfRunHooks( 'LoadExtensionSchemaUpdates', array( $this ) ); |
50 | 60 | $this->tables = $schema; |
51 | 61 | $this->addDatabaseSpecificTables(); |
52 | 62 | } |
— | — | @@ -123,6 +133,11 @@ |
124 | 134 | } |
125 | 135 | |
126 | 136 | /** |
| 137 | + * Returns database type |
| 138 | + */ |
| 139 | + abstract public function getType(); |
| 140 | + |
| 141 | + /** |
127 | 142 | * Given an abstract table definition, return a DBMS-specific command to |
128 | 143 | * create it. |
129 | 144 | * @param $name The name of the table, like 'page' or 'revision' |
— | — | @@ -149,6 +164,11 @@ |
150 | 165 | } |
151 | 166 | |
152 | 167 | class MysqlSchema extends SchemaBuilder { |
| 168 | + |
| 169 | + public function getType() { |
| 170 | + return 'mysql'; |
| 171 | + } |
| 172 | + |
153 | 173 | protected function addDatabaseSpecificTables() { |
154 | 174 | $this->tables['searchindex'] = array( |
155 | 175 | 'prefix' => 'si', |
— | — | @@ -228,9 +248,9 @@ |
229 | 249 | } |
230 | 250 | $sql .= "{$this->tblPrefix}{$idx} ON $tblName ("; |
231 | 251 | foreach( $idxDef as $col ) { |
232 | | - $sql .= "{$prefix}{$col},"; |
| 252 | + $sql .= "{$prefix}{$col}, "; |
233 | 253 | } |
234 | | - $sql = rtrim( $sql, ',' ); |
| 254 | + $sql = rtrim( $sql, ', ' ); |
235 | 255 | $sql .= ");\n"; |
236 | 256 | } |
237 | 257 | } |
— | — | @@ -355,7 +375,11 @@ |
356 | 376 | 'char' => 'TEXT', |
357 | 377 | 'none' => '', |
358 | 378 | ); |
359 | | - |
| 379 | + |
| 380 | + public function getType() { |
| 381 | + return 'sqlite'; |
| 382 | + } |
| 383 | + |
360 | 384 | /** |
361 | 385 | * @todo: update updatelog with fts3 |
362 | 386 | */ |
— | — | @@ -368,10 +392,10 @@ |
369 | 393 | 'virtual' => 'FTS3', |
370 | 394 | 'fields' => array( |
371 | 395 | 'title' => array( |
372 | | - 'type' => Schema::TYPE_NONE, |
| 396 | + 'type' => 'none', |
373 | 397 | ), |
374 | 398 | 'text' => array( |
375 | | - 'type' => Schema::TYPE_NONE, |
| 399 | + 'type' => 'none', |
376 | 400 | ), |
377 | 401 | ) |
378 | 402 | ); |
— | — | @@ -380,13 +404,16 @@ |
381 | 405 | 'prefix' => 'si', |
382 | 406 | 'fields' => array( |
383 | 407 | 'title' => array( |
384 | | - 'type' => Schema::TYPE_TEXT, |
| 408 | + 'type' => 'text', |
385 | 409 | ), |
386 | 410 | 'text' => array( |
387 | | - 'type' => Schema::TYPE_TEXT, |
| 411 | + 'type' => 'text', |
388 | 412 | ), |
389 | 413 | ) |
390 | 414 | ); |
| 415 | + $this->tablesToDelete[] = array_merge( $this->tablesToDelete, |
| 416 | + array( 'searchindex_content', 'searchindex_segdir', 'searchindex_segments' ) |
| 417 | + ); |
391 | 418 | } |
392 | 419 | $db->close(); |
393 | 420 | unlink( $tmpFile ); |
— | — | @@ -418,9 +445,9 @@ |
419 | 446 | } |
420 | 447 | $sql .= "{$this->tblPrefix}{$idx} ON $tblName ("; |
421 | 448 | foreach( $idxDef as $col ) { |
422 | | - $sql .= "{$prefix}{$col},"; |
| 449 | + $sql .= "{$prefix}{$col}, "; |
423 | 450 | } |
424 | | - $sql = rtrim( $sql, ',' ); |
| 451 | + $sql = rtrim( $sql, ', ' ); |
425 | 452 | $sql .= ");\n"; |
426 | 453 | } |
427 | 454 | } |