3 * Oracle-specific installer.
10 * Class for setting up the MediaWiki database using Oracle.
15 class OracleInstaller
extends DatabaseInstaller
{
17 protected $globalNames = array(
25 protected $internalDefaults = array(
26 '_OracleDefTS' => 'USERS',
27 '_OracleTempTS' => 'TEMP',
28 '_OracleUseSysdba' => true
31 public $minimumVersion = '9.0.1'; // 9iR1
33 public function getName() {
37 public function isCompiled() {
38 return self
::checkExtension( 'oci8' );
41 public function getWebUserBox( $noCreateMsg = false ) {
42 $this->parent
->setVar( '_SameAccount', false );
43 $this->parent
->setVar( '_CreateDBAccount', true );
44 $this->parent
->setVar( 'wgDBname', '' );
45 return Html
::openElement( 'fieldset' ) .
46 Html
::element( 'legend', array(), wfMsg( 'config-db-web-account' ) ) .
47 Html
::openElement( 'div', array( 'id' => 'dbOtherAccount' ) ) .
48 $this->getTextBox( 'wgDBuser', 'config-db-username' ) .
49 $this->getPasswordBox( 'wgDBpassword', 'config-db-password', array(), $this->parent
->getHelpBox( 'config-db-web-help' ) ) .
50 $this->getCheckBox( '_CreateDBAccount', 'config-db-web-create', array( 'disabled' => true ) ).
51 Html
::closeElement( 'div' ) . Html
::closeElement( 'fieldset' );
54 public function getConnectForm() {
55 $this->parent
->setVar( '_InstallUser', 'sys' );
56 $this->parent
->setVar( 'wgDBserver', '' );
58 $this->getTextBox( 'wgDBserver', 'config-db-host-oracle', array(), $this->parent
->getHelpBox( 'config-db-host-oracle-help' ) ) .
59 Html
::openElement( 'fieldset' ) .
60 Html
::element( 'legend', array(), wfMsg( 'config-db-wiki-settings' ) ) .
61 $this->getTextBox( 'wgDBprefix', 'config-db-prefix' ) .
62 $this->getTextBox( '_OracleDefTS', 'config-oracle-def-ts' ) .
63 $this->getTextBox( '_OracleTempTS', 'config-oracle-temp-ts', array(), $this->parent
->getHelpBox( 'config-db-oracle-help' ) ) .
64 Html
::closeElement( 'fieldset' ) .
65 $this->getInstallUserBox().
66 $this->getWebUserBox();
69 public function submitConnectForm() {
70 // Get variables from the request
71 $newValues = $this->setVarsFromRequest( array( 'wgDBserver', 'wgDBprefix', 'wgDBuser', 'wgDBpassword' ) );
72 $this->parent
->setVar( 'wgDBname', $this->getVar( 'wgDBuser' ) );
75 $status = Status
::newGood();
76 if ( !strlen( $newValues['wgDBserver'] ) ) {
77 $status->fatal( 'config-missing-db-server-oracle' );
78 } elseif ( !preg_match( '/^[a-zA-Z0-9_\.]+$/', $newValues['wgDBserver'] ) ) {
79 $status->fatal( 'config-invalid-db-server-oracle', $newValues['wgDBserver'] );
81 if ( !preg_match( '/^[a-zA-Z0-9_]*$/', $newValues['wgDBprefix'] ) ) {
82 $status->fatal( 'config-invalid-schema', $newValues['wgDBprefix'] );
84 if ( !$status->isOK() ) {
89 $status = $this->submitInstallUserBox();
90 if ( !$status->isOK() ) {
95 $status = $this->getConnection();
96 if ( !$status->isOK() ) {
99 $conn = $status->value
;
102 $version = $conn->getServerVersion();
103 if ( version_compare( $version, $this->minimumVersion
) < 0 ) {
104 return Status
::newFatal( 'config-oracle-old', $this->minimumVersion
, $version );
110 public function getConnection() {
111 $status = Status
::newGood();
113 if ( $this->getVar( '_OracleUseSysdba' ) ) {
114 $this->db
= new DatabaseOracle(
115 $this->getVar( 'wgDBserver' ),
116 $this->getVar( '_InstallUser' ),
117 $this->getVar( '_InstallPassword' ),
118 $this->getVar( 'wgDBname' ),
120 $this->getVar( 'wgDBprefix' )
123 $this->db
= new DatabaseOracle(
124 $this->getVar( 'wgDBserver' ),
125 $this->getVar( 'wgDBuser' ),
126 $this->getVar( 'wgDBpassword' ),
127 $this->getVar( 'wgDBname' ),
129 $this->getVar( 'wgDBprefix' )
132 $status->value
= $this->db
;
133 } catch ( DBConnectionError
$e ) {
134 $status->fatal( 'config-connection-error', $e->getMessage() );
139 public function needsUpgrade() {
140 $tempDBname = $this->getVar( 'wgDBname' );
141 $this->parent
->setVar( 'wgDBname', $this->getVar( 'wgDBuser' ) );
142 $retVal = parent
::needsUpgrade();
143 $this->parent
->setVar( 'wgDBname', $tempDBname );
147 public function preInstall() {
148 # Add our user callback to installSteps, right before the tables are created.
152 'callback' => array( $this, 'setupUser' ),
155 $this->parent
->addInstallStepFollowing( "database", $callback );
159 public function setupDatabase() {
160 $this->parent
->setVar( '_OracleUseSysdba', false );
161 $status = Status
::newGood();
165 public function setupUser() {
168 if ( !$this->getVar( '_CreateDBAccount' ) ) {
169 return Status
::newGood();
171 $status = $this->getConnection();
172 if ( !$status->isOK() ) {
176 if ( !$this->db
->selectDB( $this->getVar( 'wgDBuser' ) ) ) {
177 global $_OracleDefTS, $_OracleTempTS;
178 $_OracleDefTS = $this->getVar( '_OracleDefTS' );
179 $_OracleTempTS = $this->getVar( '_OracleTempTS' );
180 $error = $this->db
->sourceFile( "$IP/maintenance/oracle/user.sql" );
181 if ( $error !== true ||
!$this->db
->selectDB( $this->getVar( 'wgDBuser' ) ) ) {
182 $status->fatal( 'config-install-user-failed', $this->getVar( 'wgDBuser' ), $error );
190 * Overload: after this action field info table has to be rebuilt
192 public function createTables() {
193 $status = parent
::createTables();
195 $this->db
->doQuery( 'BEGIN fill_wiki_info; END;' );
201 public function getLocalSettings() {
202 $prefix = $this->getVar( 'wgDBprefix' );
204 "# Oracle specific settings
205 \$wgDBprefix = \"{$prefix}\";