From e1c8e802970f6a8f0b85843ee09a368702036efe Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Thu, 27 Jan 2011 08:25:48 +0000 Subject: [PATCH] * Fixed Oracle new installer support, broken by r80957. This is a minimal patch and doesn't address the architectural issues. ** Moved the responsibility for calling setupSchemaVars() on install to the DatabaseInstaller subclass. This allows it to be called after setupDatabase() has completed, as required by Oracle and PostgreSQL. ** Fixed OracleInstaller::getConnection() so that it respects $this->useSysDBA correctly. ** In OracleInstaller, added some more variables to the list of schema vars, which are needed by user.sql and tables.sql ** In SearchOracle, specify the database name when calling ctx_ddl.sync_index(). This fixes a fatal error in the createMainpage step, caused by the schema name not being equal to the current user. * In oracle/tables.sql, fixed a couple of indexes with missing table prefixes. * Improved debugging output in DatabaseInstaller::getConnection() and Installer::createMainpage(). * In DatabaseBase::selectDB(), set $this->mDBname correctly, as in DatabaseMysql. --- includes/db/Database.php | 1 + includes/db/DatabaseOracle.php | 10 +++- includes/installer/DatabaseInstaller.php | 2 + includes/installer/Installer.i18n.php | 2 +- includes/installer/Installer.php | 1 - includes/installer/MysqlInstaller.php | 1 + includes/installer/OracleInstaller.php | 65 +++++++++++++++++++++--- includes/installer/PostgresInstaller.php | 1 + includes/installer/SqliteInstaller.php | 1 + includes/search/SearchOracle.php | 12 ++++- maintenance/oracle/tables.sql | 4 +- 11 files changed, 85 insertions(+), 15 deletions(-) diff --git a/includes/db/Database.php b/includes/db/Database.php index 3e0e70a51d..55148e37ed 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -1474,6 +1474,7 @@ abstract class DatabaseBase implements DatabaseType { # Stub. Shouldn't cause serious problems if it's not overridden, but # if your database engine supports a concept similar to MySQL's # databases you may as well. + $this->mDBname = $db; return true; } diff --git a/includes/db/DatabaseOracle.php b/includes/db/DatabaseOracle.php index 2810429ce9..ed8a0684b8 100644 --- a/includes/db/DatabaseOracle.php +++ b/includes/db/DatabaseOracle.php @@ -1086,10 +1086,16 @@ class DatabaseOracle extends DatabaseBase { } function selectDB( $db ) { - if ( $db == null || $db == $this->mUser ) { return true; } + $this->mDBname = $db; + if ( $db == null || $db == $this->mUser ) { + return true; + } $sql = 'ALTER SESSION SET CURRENT_SCHEMA=' . strtoupper($db); $stmt = oci_parse( $this->mConn, $sql ); - if ( !oci_execute( $stmt ) ) { + wfSuppressWarnings(); + $success = oci_execute( $stmt ); + wfRestoreWarnings(); + if ( !$success ) { $e = oci_error( $stmt ); if ( $e['code'] != '1435' ) { $this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ ); diff --git a/includes/installer/DatabaseInstaller.php b/includes/installer/DatabaseInstaller.php index b85f02d5d4..38367c43b5 100644 --- a/includes/installer/DatabaseInstaller.php +++ b/includes/installer/DatabaseInstaller.php @@ -195,6 +195,8 @@ abstract class DatabaseInstaller { $status = $this->getConnection(); if ( $status->isOK() ) { $status->value->setSchemaVars( $this->getSchemaVars() ); + } else { + throw new MWException( __METHOD__.': unexpected DB connection error' ); } } diff --git a/includes/installer/Installer.i18n.php b/includes/installer/Installer.i18n.php index c703ac73ab..7aac32dab2 100644 --- a/includes/installer/Installer.i18n.php +++ b/includes/installer/Installer.i18n.php @@ -471,7 +471,7 @@ Consider changing it manually.", 'config-install-sysop' => 'Creating administrator user account', 'config-install-subscribe-fail' => 'Unable to subscribe to mediawiki-announce', 'config-install-mainpage' => 'Creating main page with default content', - 'config-install-mainpage-failed' => 'Could not insert main page.', + 'config-install-mainpage-failed' => 'Could not insert main page: $1', 'config-install-done' => "'''Congratulations!''' You have successfully installed MediaWiki. diff --git a/includes/installer/Installer.php b/includes/installer/Installer.php index ab449c04bb..d19a33cf61 100644 --- a/includes/installer/Installer.php +++ b/includes/installer/Installer.php @@ -1272,7 +1272,6 @@ abstract class Installer { $installResults = array(); $installer = $this->getDBInstaller(); $installer->preInstall(); - $installer->setupSchemaVars(); $steps = $this->getInstallSteps( $installer ); foreach( $steps as $stepObj ) { $name = $stepObj['name']; diff --git a/includes/installer/MysqlInstaller.php b/includes/installer/MysqlInstaller.php index 2f65bc63b7..938d59f878 100644 --- a/includes/installer/MysqlInstaller.php +++ b/includes/installer/MysqlInstaller.php @@ -414,6 +414,7 @@ class MysqlInstaller extends DatabaseInstaller { $conn->query( "CREATE DATABASE " . $conn->addIdentifierQuotes( $dbName ), __METHOD__ ); $conn->selectDB( $dbName ); } + $this->setupSchemaVars(); return $status; } diff --git a/includes/installer/OracleInstaller.php b/includes/installer/OracleInstaller.php index 8d6ebb614a..337b4d6e3a 100644 --- a/includes/installer/OracleInstaller.php +++ b/includes/installer/OracleInstaller.php @@ -31,6 +31,8 @@ class OracleInstaller extends DatabaseInstaller { public $minimumVersion = '9.0.1'; // 9iR1 + protected $sysConn, $userConn; + public function getName() { return 'oracle'; } @@ -117,7 +119,7 @@ class OracleInstaller extends DatabaseInstaller { $this->getVar( 'wgDBserver' ), $this->getVar( '_InstallUser' ), $this->getVar( '_InstallPassword' ), - $this->getVar( 'wgDBname' ), + $this->getVar( '_InstallUser' ), DBO_SYSDBA | DBO_DDLMODE, $this->getVar( 'wgDBprefix' ) ); @@ -138,6 +140,42 @@ class OracleInstaller extends DatabaseInstaller { return $status; } + /** + * Cache the two different types of connection which can be returned by + * openConnection(). + * + * $this->db will be set to the last used connection object. + * + * FIXME: openConnection() should not be doing two different things. + */ + public function getConnection() { + // Check cache + if ( $this->useSysDBA ) { + $conn = $this->sysConn; + } else { + $conn = $this->userConn; + } + if ( $conn !== null ) { + $this->db = $conn; + return Status::newGood( $conn ); + } + + // Open a new connection + $status = $this->openConnection(); + if ( !$status->isOK() ) { + return $status; + } + + // Save to the cache + if ( $this->useSysDBA ) { + $this->sysConn = $status->value; + } else { + $this->userConn = $status->value; + } + $this->db = $status->value; + return $status; + } + public function needsUpgrade() { $tempDBname = $this->getVar( 'wgDBname' ); $this->parent->setVar( 'wgDBname', $this->getVar( 'wgDBuser' ) ); @@ -175,6 +213,8 @@ class OracleInstaller extends DatabaseInstaller { return $status; } + $this->setupSchemaVars(); + if ( !$this->db->selectDB( $this->getVar( 'wgDBuser' ) ) ) { $this->db->setFlag( DBO_DDLMODE ); $error = $this->db->sourceFile( "$IP/maintenance/oracle/user.sql" ); @@ -183,6 +223,7 @@ class OracleInstaller extends DatabaseInstaller { } } + return $status; } @@ -190,6 +231,8 @@ class OracleInstaller extends DatabaseInstaller { * Overload: after this action field info table has to be rebuilt */ public function createTables() { + $this->setupSchemaVars(); + $this->db->selectDB( $this->getVar( 'wgDBuser' ) ); $status = parent::createTables(); $this->db->query( 'BEGIN fill_wiki_info; END;' ); @@ -198,13 +241,21 @@ class OracleInstaller extends DatabaseInstaller { } public function getSchemaVars() { - /** - * The variables $_OracleDefTS, $_OracleTempTS are used by maintenance/oracle/user.sql - */ - return array( - '_OracleDefTS' => $this->getVar( '_OracleDefTS' ), - '_OracleTempTS' => $this->getVar( '_OracleTempTS' ), + $varNames = array( + # These variables are used by maintenance/oracle/user.sql + '_OracleDefTS', + '_OracleTempTS', + 'wgDBuser', + 'wgDBpassword', + + # These are used by tables.sql + 'wgDBprefix', ); + $vars = array(); + foreach ( $varNames as $name ) { + $vars[$name] = $this->getVar( $name ); + } + return $vars; } public function getLocalSettings() { diff --git a/includes/installer/PostgresInstaller.php b/includes/installer/PostgresInstaller.php index 94d33ee989..6202364d38 100644 --- a/includes/installer/PostgresInstaller.php +++ b/includes/installer/PostgresInstaller.php @@ -215,6 +215,7 @@ class PostgresInstaller extends DatabaseInstaller { if ( !$status->isOK() ) { return $status; } + $this->setupSchemaVars(); $conn = $status->value; $dbName = $this->getVar( 'wgDBname' ); diff --git a/includes/installer/SqliteInstaller.php b/includes/installer/SqliteInstaller.php index 413f297941..0daf37fccc 100644 --- a/includes/installer/SqliteInstaller.php +++ b/includes/installer/SqliteInstaller.php @@ -144,6 +144,7 @@ class SqliteInstaller extends DatabaseInstaller { $this->setVar( 'wgDBserver', '' ); $this->setVar( 'wgDBuser', '' ); $this->setVar( 'wgDBpassword', '' ); + $this->setupSchemaVars(); return $this->getConnection(); } diff --git a/includes/search/SearchOracle.php b/includes/search/SearchOracle.php index bc5f6b51e7..4035fc3d54 100644 --- a/includes/search/SearchOracle.php +++ b/includes/search/SearchOracle.php @@ -246,8 +246,16 @@ class SearchOracle extends SearchEngine { 'si_title' => $title, 'si_text' => $text ), 'SearchOracle::update' ); - $dbw->query("CALL ctx_ddl.sync_index('si_text_idx')"); - $dbw->query("CALL ctx_ddl.sync_index('si_title_idx')"); + + // Sync the index + // We need to specify the DB name (i.e. user/schema) here so that + // it can work from the installer, where + // ALTER SESSION SET CURRENT_SCHEMA = ... + // was used. + $dbw->query( "CALL ctx_ddl.sync_index(" . + $dbw->addQuotes( $dbw->getDBname() . '.si_text_idx' ) . ")" ); + $dbw->query( "CALL ctx_ddl.sync_index(" . + $dbw->addQuotes( $dbw->getDBname() . '.si_title_idx' ) . ")" ); } /** diff --git a/maintenance/oracle/tables.sql b/maintenance/oracle/tables.sql index 217fe1fa9b..6d57c7cddb 100644 --- a/maintenance/oracle/tables.sql +++ b/maintenance/oracle/tables.sql @@ -610,8 +610,8 @@ ALTER TABLE &mw_prefix.valid_tag ADD CONSTRAINT &mw_prefix.valid_tag_pk PRIMARY --); --CREATE UNIQUE INDEX &mw_prefix.profiling_u01 ON &mw_prefix.profiling (pf_name, pf_server); -CREATE INDEX si_title_idx ON &mw_prefix.searchindex(si_title) INDEXTYPE IS ctxsys.context; -CREATE INDEX si_text_idx ON &mw_prefix.searchindex(si_text) INDEXTYPE IS ctxsys.context; +CREATE INDEX &mw_prefix.si_title_idx ON &mw_prefix.searchindex(si_title) INDEXTYPE IS ctxsys.context; +CREATE INDEX &mw_prefix.si_text_idx ON &mw_prefix.searchindex(si_text) INDEXTYPE IS ctxsys.context; CREATE TABLE &mw_prefix.l10n_cache ( lc_lang varchar2(32) NOT NULL, -- 2.20.1