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 function getName() {
35 public function isCompiled() {
36 return self
::checkExtension( 'oci8' );
39 public function getWebUserBox( $noCreateMsg = false ) {
40 $name = $this->getName();
41 $this->parent
->setVar( '_SameAccount', false );
42 $this->parent
->setVar( '_CreateDBAccount', true );
43 $this->parent
->setVar( 'wgDBname', '' );
44 return Xml
::openElement( 'fieldset' ) .
45 Xml
::element( 'legend', array(), wfMsg( 'config-db-web-account' ) ) .
46 Xml
::openElement( 'div', array( 'id' => 'dbOtherAccount' ) ) .
47 $this->getTextBox( 'wgDBuser', 'config-db-username' ) .
48 $this->getPasswordBox( 'wgDBpassword', 'config-db-password' ) .
49 $this->parent
->getHelpBox( 'config-db-web-help' ).
50 $this->getCheckBox( '_CreateDBAccount', 'config-db-web-create', array( 'disabled' => true ) ).
51 Xml
::closeElement( 'div' ) . Xml
::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' ) .
59 $this->parent
->getHelpBox( 'config-db-host-oracle-help' ) .
60 Xml
::openElement( 'fieldset' ) .
61 Xml
::element( 'legend', array(), wfMsg( 'config-db-wiki-settings' ) ) .
62 $this->getTextBox( 'wgDBprefix', 'config-db-prefix' ) .
63 $this->getTextBox( '_OracleDefTS', 'config-oracle-def-ts' ) .
64 $this->getTextBox( '_OracleTempTS', 'config-oracle-temp-ts' ) .
65 $this->parent
->getHelpBox( 'config-db-oracle-help' ) .
66 Xml
::closeElement( 'fieldset' ) .
67 $this->getInstallUserBox().
68 $this->getWebUserBox();
71 public function submitConnectForm() {
72 // Get variables from the request
73 $newValues = $this->setVarsFromRequest( array( 'wgDBserver', 'wgDBprefix', 'wgDBuser', 'wgDBpassword' ) );
74 $this->parent
->setVar( 'wgDBname', $this->getVar( 'wgDBuser' ) );
77 $status = Status
::newGood();
78 if ( !strlen( $newValues['wgDBserver'] ) ) {
79 $status->fatal( 'config-missing-db-server-oracle' );
80 } elseif ( !preg_match( '/^[a-zA-Z0-9_\.]+$/', $newValues['wgDBserver'] ) ) {
81 $status->fatal( 'config-invalid-db-server-oracle', $newValues['wgDBserver'] );
83 if ( !preg_match( '/^[a-zA-Z0-9_]*$/', $newValues['wgDBprefix'] ) ) {
84 $status->fatal( 'config-invalid-schema', $newValues['wgDBprefix'] );
86 if ( !$status->isOK() ) {
91 $status = $this->submitInstallUserBox();
92 if ( !$status->isOK() ) {
97 $status = $this->getConnection();
98 if ( !$status->isOK() ) {
101 $conn = $status->value
;
105 $version = $conn->getServerVersion();
106 if ( version_compare( $version, $this->minimumVersion ) < 0 ) {
107 return Status::newFatal( 'config-mysql-old', $this->minimumVersion, $version );
113 public function getConnection() {
114 $status = Status
::newGood();
116 if ( $this->getVar( '_OracleUseSysdba' ) ) {
117 $this->db
= new DatabaseOracle(
118 $this->getVar( 'wgDBserver' ),
119 $this->getVar( '_InstallUser' ),
120 $this->getVar( '_InstallPassword' ),
121 $this->getVar( 'wgDBname' ),
124 $this->getVar( 'wgDBprefix' )
127 $this->db
= new DatabaseOracle(
128 $this->getVar( 'wgDBserver' ),
129 $this->getVar( 'wgDBuser' ),
130 $this->getVar( 'wgDBpassword' ),
131 $this->getVar( 'wgDBname' ),
134 $this->getVar( 'wgDBprefix' )
137 $status->value
= $this->db
;
138 } catch ( DBConnectionError
$e ) {
139 $status->fatal( 'config-connection-error', $e->getMessage() );
144 public function needsUpgrade() {
145 $tempDBname = $this->getVar( 'wgDBname' );
146 $this->parent
->setVar( 'wgDBname', $this->getVar( 'wgDBuser' ) );
147 $retVal = parent
::needsUpgrade();
148 $this->parent
->setVar( 'wgDBname', $tempDBname );
152 public function preInstall() {
153 # Add our user callback to installSteps, right before the tables are created.
157 'callback' => array( $this, 'setupUser' ),
160 $this->parent
->addInstallStepFollowing( "database", $callback );
164 public function setupDatabase() {
165 $this->parent
->setVar( '_OracleUseSysdba', false );
166 $status = Status
::newGood();
170 public function setupUser() {
173 if ( !$this->getVar( '_CreateDBAccount' ) ) {
174 return Status
::newGood();
176 $status = $this->getConnection();
177 if ( !$status->isOK() ) {
181 global $_OracleDefTS, $_OracleTempTS;
182 $_OracleDefTS = $this->getVar( '_OracleDefTS' );
183 $_OracleTempTS = $this->getVar( '_OracleTempTS' );
184 $error = $this->db
->sourceFile( "$IP/maintenance/oracle/user.sql" );
185 if ( $error !== true ||
!$this->db
->selectDB( $this->getVar( 'wgDBuser' ) ) ) {
186 $status->fatal( 'config-install-user-failed', $this->getVar( 'wgDBuser' ), $error );
192 public function getLocalSettings() {
193 $prefix = $this->getVar( 'wgDBprefix' );
195 "# Oracle specific settings
196 \$wgDBprefix = \"{$prefix}\";";
199 public function doUpgrade() {