From ed7ff76d50fe26b7c9ded7025cd0ff57bedb09ee Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Wed, 1 Sep 2010 19:03:56 +0000 Subject: [PATCH] Move createTables() up a level, this code was practically identical --- includes/db/Database.php | 12 ++++++++++++ includes/installer/DatabaseInstaller.php | 20 +++++++++++++++++++- includes/installer/MysqlInstaller.php | 20 -------------------- includes/installer/OracleInstaller.php | 4 ---- includes/installer/PostgresInstaller.php | 16 ---------------- includes/installer/SqliteInstaller.php | 18 +++--------------- 6 files changed, 34 insertions(+), 56 deletions(-) diff --git a/includes/db/Database.php b/includes/db/Database.php index 388a81e9a9..4f2217dadd 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -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 #------------------------------------------------------------------------------ diff --git a/includes/installer/DatabaseInstaller.php b/includes/installer/DatabaseInstaller.php index d3727d87b7..099742f6dc 100644 --- a/includes/installer/DatabaseInstaller.php +++ b/includes/installer/DatabaseInstaller.php @@ -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. diff --git a/includes/installer/MysqlInstaller.php b/includes/installer/MysqlInstaller.php index 7be7ff6ab3..c6bea9c5fa 100644 --- a/includes/installer/MysqlInstaller.php +++ b/includes/installer/MysqlInstaller.php @@ -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' ) ); diff --git a/includes/installer/OracleInstaller.php b/includes/installer/OracleInstaller.php index 789ccfffbe..0280836ac0 100644 --- a/includes/installer/OracleInstaller.php +++ b/includes/installer/OracleInstaller.php @@ -96,10 +96,6 @@ class OracleInstaller extends DatabaseInstaller { // TODO } - public function createTables() { - // TODO - } - public function getLocalSettings() { $prefix = $this->getVar( 'wgDBprefix' ); return diff --git a/includes/installer/PostgresInstaller.php b/includes/installer/PostgresInstaller.php index 8e9fdb4661..48602a7a0e 100644 --- a/includes/installer/PostgresInstaller.php +++ b/includes/installer/PostgresInstaller.php @@ -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' ); diff --git a/includes/installer/SqliteInstaller.php b/includes/installer/SqliteInstaller.php index 08eea76b22..e1f6985f23 100644 --- a/includes/installer/SqliteInstaller.php +++ b/includes/installer/SqliteInstaller.php @@ -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 ) { -- 2.20.1