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 public $minimumVersion = '9.0.1'; // 9iR1
32 protected $connError = null;
34 public function getName() {
38 public function isCompiled() {
39 return self
::checkExtension( 'oci8' );
42 public function getConnectForm() {
43 if ( $this->getVar( 'wgDBserver' ) == 'localhost' ) {
44 $this->parent
->setVar( 'wgDBserver', '' );
47 $this->getTextBox( 'wgDBserver', 'config-db-host-oracle', array(), $this->parent
->getHelpBox( 'config-db-host-oracle-help' ) ) .
48 Html
::openElement( 'fieldset' ) .
49 Html
::element( 'legend', array(), wfMsg( 'config-db-wiki-settings' ) ) .
50 $this->getTextBox( 'wgDBprefix', 'config-db-prefix' ) .
51 $this->getTextBox( '_OracleDefTS', 'config-oracle-def-ts' ) .
52 $this->getTextBox( '_OracleTempTS', 'config-oracle-temp-ts', array(), $this->parent
->getHelpBox( 'config-db-oracle-help' ) ) .
53 Html
::closeElement( 'fieldset' ) .
54 $this->parent
->getWarningBox( wfMsg( 'config-db-account-oracle-warn' ) ).
55 $this->getInstallUserBox().
56 $this->getWebUserBox();
59 public function submitInstallUserBox() {
60 parent
::submitInstallUserBox();
61 $this->parent
->setVar( '_InstallDBname', $this->getVar( '_InstallUser' ) );
62 return Status
::newGood();
65 public function submitConnectForm() {
66 // Get variables from the request
67 $newValues = $this->setVarsFromRequest( array( 'wgDBserver', 'wgDBprefix', 'wgDBuser', 'wgDBpassword' ) );
68 $this->parent
->setVar( 'wgDBname', $this->getVar( 'wgDBuser' ) );
71 $status = Status
::newGood();
72 if ( !strlen( $newValues['wgDBserver'] ) ) {
73 $status->fatal( 'config-missing-db-server-oracle' );
74 } elseif ( !preg_match( '/^[a-zA-Z0-9_\.]+$/', $newValues['wgDBserver'] ) ) {
75 $status->fatal( 'config-invalid-db-server-oracle', $newValues['wgDBserver'] );
77 if ( !preg_match( '/^[a-zA-Z0-9_]*$/', $newValues['wgDBprefix'] ) ) {
78 $status->fatal( 'config-invalid-schema', $newValues['wgDBprefix'] );
80 if ( !$status->isOK() ) {
85 $status = $this->submitInstallUserBox();
86 if ( !$status->isOK() ) {
90 // Try to connect trough multiple scenarios
91 // Scenario 1: Install with a manually created account
92 $status = $this->getConnection();
93 if ( !$status->isOK() ) {
94 if ( $this->connError
== 28009 ) {
95 // _InstallUser seems to be a SYSDBA
96 // Scenario 2: Create user with SYSDBA and install with new user
97 $status = $this->submitWebUserBox();
98 if ( !$status->isOK() ) {
101 $status = $this->openSYSDBAConnection();
102 if ( !$status->isOK() ) {
105 if ( !$this->getVar( '_CreateDBAccount' ) ) {
106 $status->fatal('config-db-sys-create-oracle');
112 // check for web user credentials
113 // Scenario 3: Install with a priviliged user but use a restricted user
114 $statusIS3 = $this->submitWebUserBox();
115 if ( !$statusIS3->isOK() ) {
119 $conn = $status->value
;
122 $version = $conn->getServerVersion();
123 if ( version_compare( $version, $this->minimumVersion
) < 0 ) {
124 return Status
::newFatal( 'config-oracle-old', $this->minimumVersion
, $version );
130 public function openConnection() {
131 $status = Status
::newGood();
133 $db = new DatabaseOracle(
134 $this->getVar( 'wgDBserver' ),
135 $this->getVar( '_InstallUser' ),
136 $this->getVar( '_InstallPassword' ),
137 $this->getVar( '_InstallDBname' ),
139 $this->getVar( 'wgDBprefix' )
141 $status->value
= $db;
142 } catch ( DBConnectionError
$e ) {
143 $this->connError
= $e->db
->lastErrno();
144 $status->fatal( 'config-connection-error', $e->getMessage() );
149 public function openSYSDBAConnection() {
150 $status = Status
::newGood();
152 $db = new DatabaseOracle(
153 $this->getVar( 'wgDBserver' ),
154 $this->getVar( '_InstallUser' ),
155 $this->getVar( '_InstallPassword' ),
156 $this->getVar( '_InstallDBname' ),
158 $this->getVar( 'wgDBprefix' )
160 $status->value
= $db;
161 } catch ( DBConnectionError
$e ) {
162 $this->connError
= $e->db
->lastErrno();
163 $status->fatal( 'config-connection-error', $e->getMessage() );
168 public function needsUpgrade() {
169 $tempDBname = $this->getVar( 'wgDBname' );
170 $this->parent
->setVar( 'wgDBname', $this->getVar( 'wgDBuser' ) );
171 $retVal = parent
::needsUpgrade();
172 $this->parent
->setVar( 'wgDBname', $tempDBname );
176 public function preInstall() {
177 # Add our user callback to installSteps, right before the tables are created.
180 'callback' => array( $this, 'setupUser' )
182 $this->parent
->addInstallStep( $callback, 'database' );
186 public function setupDatabase() {
187 $status = Status
::newGood();
191 public function setupUser() {
194 if ( !$this->getVar( '_CreateDBAccount' ) ) {
195 return Status
::newGood();
198 // normaly only SYSDBA users can create accounts
199 $status = $this->openSYSDBAConnection();
200 if ( !$status->isOK() ) {
201 if ( $this->connError
== 1031 ) {
202 // insufficient privileges (looks like a normal user)
203 $status = $this->openConnection();
204 if ( !$status->isOK() ) {
211 $this->db
= $status->value
;
212 $this->setupSchemaVars();
214 if ( !$this->db
->selectDB( $this->getVar( 'wgDBuser' ) ) ) {
215 $this->db
->setFlag( DBO_DDLMODE
);
216 $error = $this->db
->sourceFile( "$IP/maintenance/oracle/user.sql" );
217 if ( $error !== true ||
!$this->db
->selectDB( $this->getVar( 'wgDBuser' ) ) ) {
218 $status->fatal( 'config-install-user-failed', $this->getVar( 'wgDBuser' ), $error );
220 } elseif ( $this->db
->getFlag( DBO_SYSDBA
) ) {
221 $status->fatal( 'config-db-sys-user-exists-oracle', $this->getVar( 'wgDBuser' ) );
224 if ($status->isOK()) {
225 // user created or already existing, switching back to a normal connection
226 // as the new user has all needed privileges to setup the rest of the schema
227 // i will be using that user as _InstallUser from this point on
228 $this->parent
->setVar( '_InstallUser', $this->getVar( 'wgDBuser' ) );
229 $this->parent
->setVar( '_InstallPassword', $this->getVar( 'wgDBpassword' ) );
230 $this->parent
->setVar( '_InstallDBname', $this->getVar( 'wgDBuser' ) );
231 $status = $this->getConnection();
238 * Overload: after this action field info table has to be rebuilt
240 public function createTables() {
241 $this->setupSchemaVars();
242 $this->db
->selectDB( $this->getVar( 'wgDBuser' ) );
243 $this->db
->setFlag( DBO_DDLMODE
);
244 $status = parent
::createTables();
245 $this->db
->clearFlag( DBO_DDLMODE
);
247 $this->db
->query( 'BEGIN fill_wiki_info; END;' );
252 public function getSchemaVars() {
254 # These variables are used by maintenance/oracle/user.sql
260 # These are used by tables.sql
264 foreach ( $varNames as $name ) {
265 $vars[$name] = $this->getVar( $name );
270 public function getLocalSettings() {
271 $prefix = $this->getVar( 'wgDBprefix' );
273 "# Oracle specific settings
274 \$wgDBprefix = \"{$prefix}\";