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 '_InstallUser' => 'SYSDBA',
31 public $minimumVersion = '9.0.1'; // 9iR1
33 protected $connError = null;
35 public function getName() {
39 public function isCompiled() {
40 return self
::checkExtension( 'oci8' );
43 public function getConnectForm() {
44 if ( $this->getVar( 'wgDBserver' ) == 'localhost' ) {
45 $this->parent
->setVar( 'wgDBserver', '' );
48 $this->getTextBox( 'wgDBserver', 'config-db-host-oracle', array(), $this->parent
->getHelpBox( 'config-db-host-oracle-help' ) ) .
49 Html
::openElement( 'fieldset' ) .
50 Html
::element( 'legend', array(), wfMsg( 'config-db-wiki-settings' ) ) .
51 $this->getTextBox( 'wgDBprefix', 'config-db-prefix' ) .
52 $this->getTextBox( '_OracleDefTS', 'config-oracle-def-ts' ) .
53 $this->getTextBox( '_OracleTempTS', 'config-oracle-temp-ts', array(), $this->parent
->getHelpBox( 'config-db-oracle-help' ) ) .
54 Html
::closeElement( 'fieldset' ) .
55 $this->parent
->getWarningBox( wfMsg( 'config-db-account-oracle-warn' ) ).
56 $this->getInstallUserBox().
57 $this->getWebUserBox();
60 public function submitInstallUserBox() {
61 parent
::submitInstallUserBox();
62 $this->parent
->setVar( '_InstallDBname', $this->getVar( '_InstallUser' ) );
63 return Status
::newGood();
66 public function submitConnectForm() {
67 // Get variables from the request
68 $newValues = $this->setVarsFromRequest( array( 'wgDBserver', 'wgDBprefix', 'wgDBuser', 'wgDBpassword' ) );
69 $this->parent
->setVar( 'wgDBname', $this->getVar( 'wgDBuser' ) );
72 $status = Status
::newGood();
73 if ( !strlen( $newValues['wgDBserver'] ) ) {
74 $status->fatal( 'config-missing-db-server-oracle' );
75 } elseif ( !preg_match( '/^[a-zA-Z0-9_\.]+$/', $newValues['wgDBserver'] ) ) {
76 $status->fatal( 'config-invalid-db-server-oracle', $newValues['wgDBserver'] );
78 if ( !preg_match( '/^[a-zA-Z0-9_]*$/', $newValues['wgDBprefix'] ) ) {
79 $status->fatal( 'config-invalid-schema', $newValues['wgDBprefix'] );
81 if ( !$status->isOK() ) {
86 $status = $this->submitInstallUserBox();
87 if ( !$status->isOK() ) {
91 // Try to connect trough multiple scenarios
92 // Scenario 1: Install with a manually created account
93 $status = $this->getConnection();
94 if ( !$status->isOK() ) {
95 if ( $this->connError
== 28009 ) {
96 // _InstallUser seems to be a SYSDBA
97 // Scenario 2: Create user with SYSDBA and install with new user
98 $status = $this->submitWebUserBox();
99 if ( !$status->isOK() ) {
102 $status = $this->openSYSDBAConnection();
103 if ( !$status->isOK() ) {
106 if ( !$this->getVar( '_CreateDBAccount' ) ) {
107 $status->fatal('config-db-sys-create-oracle');
113 // check for web user credentials
114 // Scenario 3: Install with a priviliged user but use a restricted user
115 $statusIS3 = $this->submitWebUserBox();
116 if ( !$statusIS3->isOK() ) {
122 * @var $conn DatabaseBase
124 $conn = $status->value
;
127 $version = $conn->getServerVersion();
128 if ( version_compare( $version, $this->minimumVersion
) < 0 ) {
129 return Status
::newFatal( 'config-oracle-old', $this->minimumVersion
, $version );
135 public function openConnection() {
136 $status = Status
::newGood();
138 $db = new DatabaseOracle(
139 $this->getVar( 'wgDBserver' ),
140 $this->getVar( '_InstallUser' ),
141 $this->getVar( '_InstallPassword' ),
142 $this->getVar( '_InstallDBname' ),
144 $this->getVar( 'wgDBprefix' )
146 $status->value
= $db;
147 } catch ( DBConnectionError
$e ) {
148 $this->connError
= $e->db
->lastErrno();
149 $status->fatal( 'config-connection-error', $e->getMessage() );
154 public function openSYSDBAConnection() {
155 $status = Status
::newGood();
157 $db = new DatabaseOracle(
158 $this->getVar( 'wgDBserver' ),
159 $this->getVar( '_InstallUser' ),
160 $this->getVar( '_InstallPassword' ),
161 $this->getVar( '_InstallDBname' ),
163 $this->getVar( 'wgDBprefix' )
165 $status->value
= $db;
166 } catch ( DBConnectionError
$e ) {
167 $this->connError
= $e->db
->lastErrno();
168 $status->fatal( 'config-connection-error', $e->getMessage() );
173 public function needsUpgrade() {
174 $tempDBname = $this->getVar( 'wgDBname' );
175 $this->parent
->setVar( 'wgDBname', $this->getVar( 'wgDBuser' ) );
176 $retVal = parent
::needsUpgrade();
177 $this->parent
->setVar( 'wgDBname', $tempDBname );
181 public function preInstall() {
182 # Add our user callback to installSteps, right before the tables are created.
185 'callback' => array( $this, 'setupUser' )
187 $this->parent
->addInstallStep( $callback, 'database' );
191 public function setupDatabase() {
192 $status = Status
::newGood();
196 public function setupUser() {
199 if ( !$this->getVar( '_CreateDBAccount' ) ) {
200 return Status
::newGood();
203 // normaly only SYSDBA users can create accounts
204 $status = $this->openSYSDBAConnection();
205 if ( !$status->isOK() ) {
206 if ( $this->connError
== 1031 ) {
207 // insufficient privileges (looks like a normal user)
208 $status = $this->openConnection();
209 if ( !$status->isOK() ) {
216 $this->db
= $status->value
;
217 $this->setupSchemaVars();
219 if ( !$this->db
->selectDB( $this->getVar( 'wgDBuser' ) ) ) {
220 $this->db
->setFlag( DBO_DDLMODE
);
221 $error = $this->db
->sourceFile( "$IP/maintenance/oracle/user.sql" );
222 if ( $error !== true ||
!$this->db
->selectDB( $this->getVar( 'wgDBuser' ) ) ) {
223 $status->fatal( 'config-install-user-failed', $this->getVar( 'wgDBuser' ), $error );
225 } elseif ( $this->db
->getFlag( DBO_SYSDBA
) ) {
226 $status->fatal( 'config-db-sys-user-exists-oracle', $this->getVar( 'wgDBuser' ) );
229 if ($status->isOK()) {
230 // user created or already existing, switching back to a normal connection
231 // as the new user has all needed privileges to setup the rest of the schema
232 // i will be using that user as _InstallUser from this point on
233 $this->parent
->setVar( '_InstallUser', $this->getVar( 'wgDBuser' ) );
234 $this->parent
->setVar( '_InstallPassword', $this->getVar( 'wgDBpassword' ) );
235 $this->parent
->setVar( '_InstallDBname', $this->getVar( 'wgDBuser' ) );
236 $status = $this->getConnection();
243 * Overload: after this action field info table has to be rebuilt
245 public function createTables() {
246 $this->setupSchemaVars();
247 $this->db
->selectDB( $this->getVar( 'wgDBuser' ) );
248 $this->db
->setFlag( DBO_DDLMODE
);
249 $status = parent
::createTables();
250 $this->db
->clearFlag( DBO_DDLMODE
);
252 $this->db
->query( 'BEGIN fill_wiki_info; END;' );
257 public function getSchemaVars() {
259 # These variables are used by maintenance/oracle/user.sql
265 # These are used by tables.sql
269 foreach ( $varNames as $name ) {
270 $vars[$name] = $this->getVar( $name );
275 public function getLocalSettings() {
276 $prefix = $this->getVar( 'wgDBprefix' );
278 "# Oracle specific settings
279 \$wgDBprefix = \"{$prefix}\";