r63117 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r63116‎ | r63117 | r63118 >
Date:12:36, 1 March 2010
Author:maxsem
Status:resolved (Comments)
Tags:
Comment:
Unfortunately, being absolutely abstract is impossible, so extensions will need to know more about our current schema, and have more acccess to its parts
Modified paths:
  • /branches/new-installer/phase3/includes/db/SchemaBuilder.php (modified) (history)

Diff [purge]

Index: branches/new-installer/phase3/includes/db/SchemaBuilder.php
@@ -18,7 +18,6 @@
1919 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
2020 *
2121 * @author Chad Horohoe <chad@anyonecanedit.org>
22 - * @todo Handle custom table options, eg: MyISAM for searchindex, MAX_ROWS, etc
2322 * @todo Handle lengths on indexes, eg: el_from, el_to(40)
2423 * @toto Handle REFERENCES/ON DELETE CASCADE
2524 */
@@ -35,17 +34,28 @@
3635 // Any options for the table creation. Things like ENGINE=InnoDB
3736 protected $tblOptions = array();
3837
 38+ /**
 39+ * Pieces accessible to extensions
 40+ */
 41+
3942 // Our table definition
40 - protected $tables = array();
 43+ public $tables = array();
4144
 45+ // Old tables that should be deleted if they're still present
 46+ public $tablesToDelete = array();
 47+
4248 /**
 49+ * End externally-visible fields
 50+ */
 51+
 52+ /**
4353 * Constructor. We hide it so people don't try to construct their own schema
4454 * classes. Use a sane entry point, like newFromType()
4555 *
4656 * @param $schema Array See Schema::$defaultTables for more information
4757 */
4858 private final function __construct( $schema ) {
49 - wfRunHooks( 'LoadExtensionSchemaUpdates', array( &$schema ) );
 59+ wfRunHooks( 'LoadExtensionSchemaUpdates', array( $this ) );
5060 $this->tables = $schema;
5161 $this->addDatabaseSpecificTables();
5262 }
@@ -123,6 +133,11 @@
124134 }
125135
126136 /**
 137+ * Returns database type
 138+ */
 139+ abstract public function getType();
 140+
 141+ /**
127142 * Given an abstract table definition, return a DBMS-specific command to
128143 * create it.
129144 * @param $name The name of the table, like 'page' or 'revision'
@@ -149,6 +164,11 @@
150165 }
151166
152167 class MysqlSchema extends SchemaBuilder {
 168+
 169+ public function getType() {
 170+ return 'mysql';
 171+ }
 172+
153173 protected function addDatabaseSpecificTables() {
154174 $this->tables['searchindex'] = array(
155175 'prefix' => 'si',
@@ -228,9 +248,9 @@
229249 }
230250 $sql .= "{$this->tblPrefix}{$idx} ON $tblName (";
231251 foreach( $idxDef as $col ) {
232 - $sql .= "{$prefix}{$col},";
 252+ $sql .= "{$prefix}{$col}, ";
233253 }
234 - $sql = rtrim( $sql, ',' );
 254+ $sql = rtrim( $sql, ', ' );
235255 $sql .= ");\n";
236256 }
237257 }
@@ -355,7 +375,11 @@
356376 'char' => 'TEXT',
357377 'none' => '',
358378 );
359 -
 379+
 380+ public function getType() {
 381+ return 'sqlite';
 382+ }
 383+
360384 /**
361385 * @todo: update updatelog with fts3
362386 */
@@ -368,10 +392,10 @@
369393 'virtual' => 'FTS3',
370394 'fields' => array(
371395 'title' => array(
372 - 'type' => Schema::TYPE_NONE,
 396+ 'type' => 'none',
373397 ),
374398 'text' => array(
375 - 'type' => Schema::TYPE_NONE,
 399+ 'type' => 'none',
376400 ),
377401 )
378402 );
@@ -380,13 +404,16 @@
381405 'prefix' => 'si',
382406 'fields' => array(
383407 'title' => array(
384 - 'type' => Schema::TYPE_TEXT,
 408+ 'type' => 'text',
385409 ),
386410 'text' => array(
387 - 'type' => Schema::TYPE_TEXT,
 411+ 'type' => 'text',
388412 ),
389413 )
390414 );
 415+ $this->tablesToDelete[] = array_merge( $this->tablesToDelete,
 416+ array( 'searchindex_content', 'searchindex_segdir', 'searchindex_segments' )
 417+ );
391418 }
392419 $db->close();
393420 unlink( $tmpFile );
@@ -418,9 +445,9 @@
419446 }
420447 $sql .= "{$this->tblPrefix}{$idx} ON $tblName (";
421448 foreach( $idxDef as $col ) {
422 - $sql .= "{$prefix}{$col},";
 449+ $sql .= "{$prefix}{$col}, ";
423450 }
424 - $sql = rtrim( $sql, ',' );
 451+ $sql = rtrim( $sql, ', ' );
425452 $sql .= ");\n";
426453 }
427454 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r63211Fixed r63117, updated commentsmaxsem18:05, 3 March 2010

Comments

#Comment by Catrope (talk | contribs)   14:49, 1 March 2010
+			$this->tablesToDelete[] = array_merge( $this->tablesToDelete,
+				array( 'searchindex_content', 'searchindex_segdir', 'searchindex_segments' )
+			);

Looks like the [] should be removed, unless you really want to add a partial copy of tablesToDelete to itself.

#Comment by MaxSem (talk | contribs)   18:07, 3 March 2010

Fixed in r63211.

Status & tagging log