wiki.techinc.nl/includes/installer/OracleInstaller.php

219 lines
6 KiB
PHP
Raw Normal View History

<?php
/**
* Oracle-specific installer.
*
* @file
* @ingroup Deployment
*/
2010-07-29 18:36:39 +00:00
/**
* Class for setting up the MediaWiki database using Oracle.
*
2010-07-29 18:36:39 +00:00
* @ingroup Deployment
* @since 1.17
*/
class OracleInstaller extends DatabaseInstaller {
protected $globalNames = array(
'wgDBserver',
'wgDBname',
'wgDBuser',
'wgDBpassword',
'wgDBprefix',
);
protected $internalDefaults = array(
'_OracleDefTS' => 'USERS',
'_OracleTempTS' => 'TEMP'
);
protected $useSysDBA = false;
public $minimumVersion = '9.0.1'; // 9iR1
public function getName() {
return 'oracle';
}
public function isCompiled() {
return self::checkExtension( 'oci8' );
}
public function getWebUserBox( $noCreateMsg = false ) {
$this->parent->setVar( '_SameAccount', false );
$this->parent->setVar( '_CreateDBAccount', true );
$this->parent->setVar( 'wgDBname', '' );
return Html::openElement( 'fieldset' ) .
Html::element( 'legend', array(), wfMsg( 'config-db-web-account' ) ) .
Html::openElement( 'div', array( 'id' => 'dbOtherAccount' ) ) .
$this->getTextBox( 'wgDBuser', 'config-db-username' ) .
$this->getPasswordBox( 'wgDBpassword', 'config-db-password', array(), $this->parent->getHelpBox( 'config-db-web-help' ) ) .
$this->getCheckBox( '_CreateDBAccount', 'config-db-web-create', array( 'disabled' => true ) ).
Html::closeElement( 'div' ) . Html::closeElement( 'fieldset' );
}
public function getConnectForm() {
$this->parent->setVar( '_InstallUser', 'sys' );
$this->parent->setVar( 'wgDBserver', '' );
return
$this->getTextBox( 'wgDBserver', 'config-db-host-oracle', array(), $this->parent->getHelpBox( 'config-db-host-oracle-help' ) ) .
2010-11-04 23:23:34 +00:00
Html::openElement( 'fieldset' ) .
Html::element( 'legend', array(), wfMsg( 'config-db-wiki-settings' ) ) .
$this->getTextBox( 'wgDBprefix', 'config-db-prefix' ) .
$this->getTextBox( '_OracleDefTS', 'config-oracle-def-ts' ) .
$this->getTextBox( '_OracleTempTS', 'config-oracle-temp-ts', array(), $this->parent->getHelpBox( 'config-db-oracle-help' ) ) .
2010-11-04 23:23:34 +00:00
Html::closeElement( 'fieldset' ) .
$this->getInstallUserBox().
$this->getWebUserBox();
}
public function submitConnectForm() {
// Get variables from the request
$newValues = $this->setVarsFromRequest( array( 'wgDBserver', 'wgDBprefix', 'wgDBuser', 'wgDBpassword' ) );
$this->parent->setVar( 'wgDBname', $this->getVar( 'wgDBuser' ) );
// Validate them
$status = Status::newGood();
if ( !strlen( $newValues['wgDBserver'] ) ) {
$status->fatal( 'config-missing-db-server-oracle' );
} elseif ( !preg_match( '/^[a-zA-Z0-9_\.]+$/', $newValues['wgDBserver'] ) ) {
$status->fatal( 'config-invalid-db-server-oracle', $newValues['wgDBserver'] );
}
if ( !preg_match( '/^[a-zA-Z0-9_]*$/', $newValues['wgDBprefix'] ) ) {
$status->fatal( 'config-invalid-schema', $newValues['wgDBprefix'] );
}
if ( !$status->isOK() ) {
return $status;
}
// Submit user box
$status = $this->submitInstallUserBox();
if ( !$status->isOK() ) {
return $status;
}
// Try to connect
$this->useSysDBA = true;
$status = $this->getConnection();
if ( !$status->isOK() ) {
return $status;
}
$conn = $status->value;
// Check version
$version = $conn->getServerVersion();
if ( version_compare( $version, $this->minimumVersion ) < 0 ) {
return Status::newFatal( 'config-oracle-old', $this->minimumVersion, $version );
}
return $status;
}
* Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database. * Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade. * Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this. * Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used. * Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes. * Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database. * In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary. * On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added. * Fixed several instances of inappropriate call-by-reference. * Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler. * Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892. * In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString(). * Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging. * MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
public function openConnection() {
2010-09-01 19:09:27 +00:00
$status = Status::newGood();
try {
if ( $this->useSysDBA ) {
* Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database. * Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade. * Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this. * Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used. * Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes. * Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database. * In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary. * On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added. * Fixed several instances of inappropriate call-by-reference. * Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler. * Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892. * In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString(). * Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging. * MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
$db = new DatabaseOracle(
$this->getVar( 'wgDBserver' ),
$this->getVar( '_InstallUser' ),
$this->getVar( '_InstallPassword' ),
$this->getVar( 'wgDBname' ),
DBO_SYSDBA | DBO_DDLMODE,
$this->getVar( 'wgDBprefix' )
);
} else {
* Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database. * Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade. * Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this. * Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used. * Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes. * Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database. * In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary. * On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added. * Fixed several instances of inappropriate call-by-reference. * Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler. * Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892. * In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString(). * Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging. * MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
$db = new DatabaseOracle(
$this->getVar( 'wgDBserver' ),
$this->getVar( 'wgDBuser' ),
$this->getVar( 'wgDBpassword' ),
$this->getVar( 'wgDBname' ),
0,
$this->getVar( 'wgDBprefix' )
);
}
* Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database. * Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade. * Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this. * Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used. * Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes. * Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database. * In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary. * On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added. * Fixed several instances of inappropriate call-by-reference. * Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler. * Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892. * In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString(). * Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging. * MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
$status->value = $db;
2010-09-01 19:09:27 +00:00
} catch ( DBConnectionError $e ) {
$status->fatal( 'config-connection-error', $e->getMessage() );
}
return $status;
}
public function needsUpgrade() {
$tempDBname = $this->getVar( 'wgDBname' );
$this->parent->setVar( 'wgDBname', $this->getVar( 'wgDBuser' ) );
$retVal = parent::needsUpgrade();
$this->parent->setVar( 'wgDBname', $tempDBname );
return $retVal;
}
public function preInstall() {
# Add our user callback to installSteps, right before the tables are created.
$callback = array(
'name' => 'user',
'callback' => array( $this, 'setupUser' )
);
$this->parent->addInstallStep( $callback, 'database' );
}
public function setupDatabase() {
$this->useSysDBA = false;
$status = Status::newGood();
return $status;
}
public function setupUser() {
global $IP;
if ( !$this->getVar( '_CreateDBAccount' ) ) {
return Status::newGood();
}
$this->useSysDBA = true;
$status = $this->getConnection();
if ( !$status->isOK() ) {
return $status;
}
if ( !$this->db->selectDB( $this->getVar( 'wgDBuser' ) ) ) {
$this->db->setFlag( DBO_DDLMODE );
$error = $this->db->sourceFile( "$IP/maintenance/oracle/user.sql" );
if ( $error !== true || !$this->db->selectDB( $this->getVar( 'wgDBuser' ) ) ) {
$status->fatal( 'config-install-user-failed', $this->getVar( 'wgDBuser' ), $error );
}
}
return $status;
}
/**
* Overload: after this action field info table has to be rebuilt
*/
public function createTables() {
$status = parent::createTables();
2010-12-15 20:59:29 +00:00
$this->db->query( 'BEGIN fill_wiki_info; END;' );
return $status;
}
* Fixed a bug causing the installer to ignore the "engine" and "charset" settings when installing a MySQL database. * Fixed a bug causing the engine and charset settings to not be properly preserved when adding new tables on upgrade. * Fixed total breakage of SQLite upgrade, by reusing the administrative connection to the SQLite database instead of creating a new one when wfGetDB() is called. Added LBFactory_Single to support this. * Introduced a "schema variable" concept to DatabaseBase to avoid the use of globals for communication between the installer and the Database. Removed a lot of old global variable names from Database::replaceVars(), most were only added on a whim and were never used. * Introduced DatabaseInstaller::getSchemaVars(), to allow schema variables to be supplied by the DatabaseInstaller child classes. * Removed messages config-mysql-egine-mismatch [sic] and config-mysql-charset-mismatch. In the old installer it was possible for users to request a certain character set for an upgrade, but in the new installer the question is never asked. So these warnings were shown whenever a non-default character set or engine was used in the old database. * In MysqlInstaller::preUpgrade(), fixed the incorrect strings used to identify the MySQL character sets: mysql5 instead of utf8 and mysql5-binary instead of binary. * On install, initialise the site_stats table, using code copied from the old installer. Unlike the old installer, use SiteStats to increment the user count when the initial user is added. * Fixed several instances of inappropriate call-by-reference. * Replaced call_user_func_array() with call_user_func() where possible, it is shorter and simpler. * Moved the caching boilerplate for DatabaseInstaller::getConnection() to the base class, and have the derived classes override an uncached function openConnection() instead. Updates r80892. * In MysqlInstaller::getLocalSettings(), escape PHP strings correctly with LocalSettingsGenerator::escapePhpString(). * Reduce timeout for checks in dirIsExecutable() to 3 seconds, so that it doesn't take 30s to run when apache is in single-threaded mode for debugging. * MySQL and SQLite have been tested and they appear to work. PostgreSQL upgrade is totally broken, apparently it was like that before I started. The Oracle code is untested.
2011-01-25 07:37:48 +00:00
public function getSchemaVars() {
/**
* The variables $_OracleDefTS, $_OracleTempTS are used by maintenance/oracle/user.sql
*/
return array(
'_OracleDefTS' => $this->getVar( '_OracleDefTS' ),
'_OracleTempTS' => $this->getVar( '_OracleTempTS' ),
);
}
public function getLocalSettings() {
$prefix = $this->getVar( 'wgDBprefix' );
return
"# Oracle specific settings
\$wgDBprefix = \"{$prefix}\";
";
}
}