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'
30 protected $connError = null;
32 public function getName() {
36 public function isCompiled() {
37 return self
::checkExtension( 'oci8' );
40 public function getConnectForm() {
41 if ( $this->getVar( 'wgDBserver' ) == 'localhost' ) {
42 $this->parent
->setVar( 'wgDBserver', '' );
45 $this->getTextBox( 'wgDBserver', 'config-db-host-oracle', array(), $this->parent
->getHelpBox( 'config-db-host-oracle-help' ) ) .
46 Html
::openElement( 'fieldset' ) .
47 Html
::element( 'legend', array(), wfMsg( 'config-db-wiki-settings' ) ) .
48 $this->getTextBox( 'wgDBprefix', 'config-db-prefix' ) .
49 $this->getTextBox( '_OracleDefTS', 'config-oracle-def-ts' ) .
50 $this->getTextBox( '_OracleTempTS', 'config-oracle-temp-ts', array(), $this->parent
->getHelpBox( 'config-db-oracle-help' ) ) .
51 Html
::closeElement( 'fieldset' ) .
52 $this->parent
->getWarningBox( wfMsg( 'config-db-account-oracle-warn' ) ).
53 $this->getInstallUserBox().
54 $this->getWebUserBox();
57 public function submitInstallUserBox() {
58 parent
::submitInstallUserBox();
59 $this->parent
->setVar( '_InstallDBname', $this->getVar( '_InstallUser' ) );
60 return Status
::newGood();
63 public function submitConnectForm() {
64 // Get variables from the request
65 $newValues = $this->setVarsFromRequest( array( 'wgDBserver', 'wgDBprefix', 'wgDBuser', 'wgDBpassword' ) );
66 $this->parent
->setVar( 'wgDBname', $this->getVar( 'wgDBuser' ) );
69 $status = Status
::newGood();
70 if ( !strlen( $newValues['wgDBserver'] ) ) {
71 $status->fatal( 'config-missing-db-server-oracle' );
72 } elseif ( !preg_match( '/^[a-zA-Z0-9_\.]+$/', $newValues['wgDBserver'] ) ) {
73 $status->fatal( 'config-invalid-db-server-oracle', $newValues['wgDBserver'] );
75 if ( !preg_match( '/^[a-zA-Z0-9_]*$/', $newValues['wgDBprefix'] ) ) {
76 $status->fatal( 'config-invalid-schema', $newValues['wgDBprefix'] );
78 if ( !$status->isOK() ) {
83 $status = $this->submitInstallUserBox();
84 if ( !$status->isOK() ) {
88 // Try to connect trough multiple scenarios
89 // Scenario 1: Install with a manually created account
90 $status = $this->getConnection();
91 if ( !$status->isOK() ) {
92 if ( $this->connError
== 28009 ) {
93 // _InstallUser seems to be a SYSDBA
94 // Scenario 2: Create user with SYSDBA and install with new user
95 $status = $this->submitWebUserBox();
96 if ( !$status->isOK() ) {
99 $status = $this->openSYSDBAConnection();
100 if ( !$status->isOK() ) {
103 if ( !$this->getVar( '_CreateDBAccount' ) ) {
104 $status->fatal('config-db-sys-create-oracle');
110 // check for web user credentials
111 // Scenario 3: Install with a priviliged user but use a restricted user
112 $statusIS3 = $this->submitWebUserBox();
113 if ( !$statusIS3->isOK() ) {
117 $conn = $status->value
;
120 $version = $conn->getServerVersion();
121 if ( version_compare( $version, MW_MIN_ORACLE_VERSION
) < 0 ) {
122 return Status
::newFatal( 'config-oracle-old', MW_MIN_ORACLE_VERSION
, $version );
128 public function openConnection() {
129 $status = Status
::newGood();
131 $db = new DatabaseOracle(
132 $this->getVar( 'wgDBserver' ),
133 $this->getVar( '_InstallUser' ),
134 $this->getVar( '_InstallPassword' ),
135 $this->getVar( '_InstallDBname' ),
137 $this->getVar( 'wgDBprefix' )
139 $status->value
= $db;
140 } catch ( DBConnectionError
$e ) {
141 $this->connError
= $e->db
->lastErrno();
142 $status->fatal( 'config-connection-error', $e->getMessage() );
147 public function openSYSDBAConnection() {
148 $status = Status
::newGood();
150 $db = new DatabaseOracle(
151 $this->getVar( 'wgDBserver' ),
152 $this->getVar( '_InstallUser' ),
153 $this->getVar( '_InstallPassword' ),
154 $this->getVar( '_InstallDBname' ),
156 $this->getVar( 'wgDBprefix' )
158 $status->value
= $db;
159 } catch ( DBConnectionError
$e ) {
160 $this->connError
= $e->db
->lastErrno();
161 $status->fatal( 'config-connection-error', $e->getMessage() );
166 public function needsUpgrade() {
167 $tempDBname = $this->getVar( 'wgDBname' );
168 $this->parent
->setVar( 'wgDBname', $this->getVar( 'wgDBuser' ) );
169 $retVal = parent
::needsUpgrade();
170 $this->parent
->setVar( 'wgDBname', $tempDBname );
174 public function preInstall() {
175 # Add our user callback to installSteps, right before the tables are created.
178 'callback' => array( $this, 'setupUser' )
180 $this->parent
->addInstallStep( $callback, 'database' );
184 public function setupDatabase() {
185 $status = Status
::newGood();
189 public function setupUser() {
192 if ( !$this->getVar( '_CreateDBAccount' ) ) {
193 return Status
::newGood();
196 // normaly only SYSDBA users can create accounts
197 $status = $this->openSYSDBAConnection();
198 if ( !$status->isOK() ) {
199 if ( $this->connError
== 1031 ) {
200 // insufficient privileges (looks like a normal user)
201 $status = $this->openConnection();
202 if ( !$status->isOK() ) {
209 $this->db
= $status->value
;
210 $this->setupSchemaVars();
212 if ( !$this->db
->selectDB( $this->getVar( 'wgDBuser' ) ) ) {
213 $this->db
->setFlag( DBO_DDLMODE
);
214 $error = $this->db
->sourceFile( "$IP/maintenance/oracle/user.sql" );
215 if ( $error !== true ||
!$this->db
->selectDB( $this->getVar( 'wgDBuser' ) ) ) {
216 $status->fatal( 'config-install-user-failed', $this->getVar( 'wgDBuser' ), $error );
218 } elseif ( $this->db
->getFlag( DBO_SYSDBA
) ) {
219 $status->fatal( 'config-db-sys-user-exists-oracle', $this->getVar( 'wgDBuser' ) );
222 if ($status->isOK()) {
223 // user created or already existing, switching back to a normal connection
224 // as the new user has all needed privileges to setup the rest of the schema
225 // i will be using that user as _InstallUser from this point on
226 $this->parent
->setVar( '_InstallUser', $this->getVar( 'wgDBuser' ) );
227 $this->parent
->setVar( '_InstallPassword', $this->getVar( 'wgDBpassword' ) );
228 $this->parent
->setVar( '_InstallDBname', $this->getVar( 'wgDBuser' ) );
229 $status = $this->getConnection();
236 * Overload: after this action field info table has to be rebuilt
238 public function createTables() {
239 $this->setupSchemaVars();
240 $this->db
->selectDB( $this->getVar( 'wgDBuser' ) );
241 $this->db
->setFlag( DBO_DDLMODE
);
242 $status = parent
::createTables();
243 $this->db
->clearFlag( DBO_DDLMODE
);
245 $this->db
->query( 'BEGIN fill_wiki_info; END;' );
250 public function getSchemaVars() {
252 # These variables are used by maintenance/oracle/user.sql
258 # These are used by tables.sql
262 foreach ( $varNames as $name ) {
263 $vars[$name] = $this->getVar( $name );
268 public function getLocalSettings() {
269 $prefix = $this->getVar( 'wgDBprefix' );
271 "# Oracle specific settings
272 \$wgDBprefix = \"{$prefix}\";