Move createTables() up a level, this code was practically identical
authorChad Horohoe <demon@users.mediawiki.org>
Wed, 1 Sep 2010 19:03:56 +0000 (19:03 +0000)
committerChad Horohoe <demon@users.mediawiki.org>
Wed, 1 Sep 2010 19:03:56 +0000 (19:03 +0000)
includes/db/Database.php
includes/installer/DatabaseInstaller.php
includes/installer/MysqlInstaller.php
includes/installer/OracleInstaller.php
includes/installer/PostgresInstaller.php
includes/installer/SqliteInstaller.php

index 388a81e..4f2217d 100644 (file)
@@ -276,6 +276,18 @@ abstract class DatabaseBase implements DatabaseType {
                }
        }
 
+       /**
+        * Return a path to the DBMS-specific schema, otherwise default to tables.sql
+        */
+       public function getSchema() {
+               global $IP;
+               if ( file_exists( "$IP/maintenance/" . $this->getType() . "/tables.sql" ) ) {
+                       return "$IP/maintenance/" . $this->getType() . "/tables.sql";
+               } else {
+                       return "$IP/maintenance/tables.sql";
+               }
+       }
+
 #------------------------------------------------------------------------------
 # Other functions
 #------------------------------------------------------------------------------
index d3727d8..099742f 100644 (file)
@@ -116,7 +116,25 @@ abstract class DatabaseInstaller {
         * 
         * @return Status
         */
-       public abstract function createTables();
+       public function createTables() {
+               $status = $this->getConnection();
+               if ( !$status->isOK() ) {
+                       return $status;
+               }
+               $this->db->selectDB( $this->getVar( 'wgDBname' ) );
+
+               if( $this->db->tableExists( 'user' ) ) {
+                       $status->warning( 'config-install-tables-exist' );
+                       return $status;
+               }
+
+               $error = $this->db->sourceFile( $this->db->getSchema() );
+               if( $error !== true ) {
+                       $this->db->reportQueryError( $error, 0, $sql, __METHOD__ );
+                       $status->fatal( 'config-install-tables-failed', $error );
+               }
+               return $status;
+       }
 
        /**
         * Get the DBMS-specific options for LocalSettings.php generation.
index 7be7ff6..c6bea9c 100644 (file)
@@ -466,26 +466,6 @@ class MysqlInstaller extends DatabaseInstaller {
                return $status;
        }
 
-       public function createTables() {
-               global $IP;
-               $status = $this->getConnection();
-               if ( !$status->isOK() ) {
-                       return $status;
-               }
-               $this->db->selectDB( $this->getVar( 'wgDBname' ) );
-               
-               if( $this->db->tableExists( 'user' ) ) {
-                       $status->warning( 'config-install-tables-exist' );
-                       return $status;
-               } 
-               
-               $error = $this->db->sourceFile( "$IP/maintenance/tables.sql" );
-               if( $error !== true ) {
-                       $status->fatal( 'config-install-tables-failed', $error );
-               }
-               return $status;
-       }
-
        public function getTableOptions() {
                return array( 'engine' => $this->getVar( '_MysqlEngine' ),
                        'default charset' => $this->getVar( '_MysqlCharset' ) );
index 789ccff..0280836 100644 (file)
@@ -96,10 +96,6 @@ class OracleInstaller extends DatabaseInstaller {
                // TODO
        }
 
-       public function createTables() {
-               // TODO
-       }
-
        public function getLocalSettings() {
                $prefix = $this->getVar( 'wgDBprefix' );
                return
index 8e9fdb4..48602a7 100644 (file)
@@ -115,22 +115,6 @@ class PostgresInstaller extends DatabaseInstaller {
        function setupDatabase() {
        }
 
-       function createTables() {
-               $status = $this->getConnection();
-               if ( !$status->isOK() ) {
-                       return $status;
-       }
-               $this->db->selectDB( $this->getVar( 'wgDBname' ) );
-
-               global $IP;
-               $err = $this->db->sourceFile( "$IP/maintenance/postgres/tables.sql" );
-               if ( $err !== true ) {
-                       //@todo or...?
-                       $this->db->reportQueryError( $err, 0, $sql, __FUNCTION__ );
-               }
-               return Status::newGood();
-       }
-
        function getLocalSettings() {
                $port = $this->getVar( 'wgDBport' );
                $schema = $this->getVar( 'wgDBmwschema' );
index 08eea76..e1f6985 100644 (file)
@@ -151,25 +151,13 @@ class SqliteInstaller extends DatabaseInstaller {
        }
 
        public function createTables() {
-               global $IP;
-               $status = $this->getConnection();
-               if ( !$status->isOK() ) {
-                       return $status;
-               }
-               // Process common MySQL/SQLite table definitions
-               $err = $this->db->sourceFile( "$IP/maintenance/tables.sql" );
-               if ( $err !== true ) {
-                       //@todo or...?
-                       $this->db->reportQueryError( $err, 0, $sql, __FUNCTION__ );
-               }
-               return $this->setupSearchIndex();
+               $status = parent::createTables();
+               return $this->setupSearchIndex( $status );;
        }
 
-       public function setupSearchIndex() {
+       public function setupSearchIndex( &$status ) {
                global $IP;
 
-               $status = Status::newGood();
-
                $module = $this->db->getFulltextSearchModule();
                $fts3tTable = $this->db->checkForEnabledSearch();
                if ( $fts3tTable &&  !$module ) {