3 * Oracle-specific installer.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
25 * Class for setting up the MediaWiki database using Oracle.
30 class OracleInstaller
extends DatabaseInstaller
{
32 protected $globalNames = array(
40 protected $internalDefaults = array(
41 '_OracleDefTS' => 'USERS',
42 '_OracleTempTS' => 'TEMP',
43 '_InstallUser' => 'SYSDBA',
46 public $minimumVersion = '9.0.1'; // 9iR1
48 protected $connError = null;
50 public function getName() {
54 public function isCompiled() {
55 return self
::checkExtension( 'oci8' );
58 public function getConnectForm() {
59 if ( $this->getVar( 'wgDBserver' ) == 'localhost' ) {
60 $this->parent
->setVar( 'wgDBserver', '' );
63 $this->getTextBox( 'wgDBserver', 'config-db-host-oracle', array(), $this->parent
->getHelpBox( 'config-db-host-oracle-help' ) ) .
64 Html
::openElement( 'fieldset' ) .
65 Html
::element( 'legend', array(), wfMsg( 'config-db-wiki-settings' ) ) .
66 $this->getTextBox( 'wgDBprefix', 'config-db-prefix' ) .
67 $this->getTextBox( '_OracleDefTS', 'config-oracle-def-ts' ) .
68 $this->getTextBox( '_OracleTempTS', 'config-oracle-temp-ts', array(), $this->parent
->getHelpBox( 'config-db-oracle-help' ) ) .
69 Html
::closeElement( 'fieldset' ) .
70 $this->parent
->getWarningBox( wfMsg( 'config-db-account-oracle-warn' ) ).
71 $this->getInstallUserBox().
72 $this->getWebUserBox();
75 public function submitInstallUserBox() {
76 parent
::submitInstallUserBox();
77 $this->parent
->setVar( '_InstallDBname', $this->getVar( '_InstallUser' ) );
78 return Status
::newGood();
81 public function submitConnectForm() {
82 // Get variables from the request
83 $newValues = $this->setVarsFromRequest( array( 'wgDBserver', 'wgDBprefix', 'wgDBuser', 'wgDBpassword' ) );
84 $this->parent
->setVar( 'wgDBname', $this->getVar( 'wgDBuser' ) );
87 $status = Status
::newGood();
88 if ( !strlen( $newValues['wgDBserver'] ) ) {
89 $status->fatal( 'config-missing-db-server-oracle' );
90 } elseif ( !preg_match( '/^[a-zA-Z0-9_\.]+$/', $newValues['wgDBserver'] ) ) {
91 $status->fatal( 'config-invalid-db-server-oracle', $newValues['wgDBserver'] );
93 if ( !preg_match( '/^[a-zA-Z0-9_]*$/', $newValues['wgDBprefix'] ) ) {
94 $status->fatal( 'config-invalid-schema', $newValues['wgDBprefix'] );
96 if ( !$status->isOK() ) {
101 $status = $this->submitInstallUserBox();
102 if ( !$status->isOK() ) {
106 // Try to connect trough multiple scenarios
107 // Scenario 1: Install with a manually created account
108 $status = $this->getConnection();
109 if ( !$status->isOK() ) {
110 if ( $this->connError
== 28009 ) {
111 // _InstallUser seems to be a SYSDBA
112 // Scenario 2: Create user with SYSDBA and install with new user
113 $status = $this->submitWebUserBox();
114 if ( !$status->isOK() ) {
117 $status = $this->openSYSDBAConnection();
118 if ( !$status->isOK() ) {
121 if ( !$this->getVar( '_CreateDBAccount' ) ) {
122 $status->fatal('config-db-sys-create-oracle');
128 // check for web user credentials
129 // Scenario 3: Install with a priviliged user but use a restricted user
130 $statusIS3 = $this->submitWebUserBox();
131 if ( !$statusIS3->isOK() ) {
137 * @var $conn DatabaseBase
139 $conn = $status->value
;
142 $version = $conn->getServerVersion();
143 if ( version_compare( $version, $this->minimumVersion
) < 0 ) {
144 return Status
::newFatal( 'config-oracle-old', $this->minimumVersion
, $version );
150 public function openConnection() {
151 $status = Status
::newGood();
153 $db = new DatabaseOracle(
154 $this->getVar( 'wgDBserver' ),
155 $this->getVar( '_InstallUser' ),
156 $this->getVar( '_InstallPassword' ),
157 $this->getVar( '_InstallDBname' ),
159 $this->getVar( 'wgDBprefix' )
161 $status->value
= $db;
162 } catch ( DBConnectionError
$e ) {
163 $this->connError
= $e->db
->lastErrno();
164 $status->fatal( 'config-connection-error', $e->getMessage() );
169 public function openSYSDBAConnection() {
170 $status = Status
::newGood();
172 $db = new DatabaseOracle(
173 $this->getVar( 'wgDBserver' ),
174 $this->getVar( '_InstallUser' ),
175 $this->getVar( '_InstallPassword' ),
176 $this->getVar( '_InstallDBname' ),
178 $this->getVar( 'wgDBprefix' )
180 $status->value
= $db;
181 } catch ( DBConnectionError
$e ) {
182 $this->connError
= $e->db
->lastErrno();
183 $status->fatal( 'config-connection-error', $e->getMessage() );
188 public function needsUpgrade() {
189 $tempDBname = $this->getVar( 'wgDBname' );
190 $this->parent
->setVar( 'wgDBname', $this->getVar( 'wgDBuser' ) );
191 $retVal = parent
::needsUpgrade();
192 $this->parent
->setVar( 'wgDBname', $tempDBname );
196 public function preInstall() {
197 # Add our user callback to installSteps, right before the tables are created.
200 'callback' => array( $this, 'setupUser' )
202 $this->parent
->addInstallStep( $callback, 'database' );
206 public function setupDatabase() {
207 $status = Status
::newGood();
211 public function setupUser() {
214 if ( !$this->getVar( '_CreateDBAccount' ) ) {
215 return Status
::newGood();
218 // normaly only SYSDBA users can create accounts
219 $status = $this->openSYSDBAConnection();
220 if ( !$status->isOK() ) {
221 if ( $this->connError
== 1031 ) {
222 // insufficient privileges (looks like a normal user)
223 $status = $this->openConnection();
224 if ( !$status->isOK() ) {
231 $this->db
= $status->value
;
232 $this->setupSchemaVars();
234 if ( !$this->db
->selectDB( $this->getVar( 'wgDBuser' ) ) ) {
235 $this->db
->setFlag( DBO_DDLMODE
);
236 $error = $this->db
->sourceFile( "$IP/maintenance/oracle/user.sql" );
237 if ( $error !== true ||
!$this->db
->selectDB( $this->getVar( 'wgDBuser' ) ) ) {
238 $status->fatal( 'config-install-user-failed', $this->getVar( 'wgDBuser' ), $error );
240 } elseif ( $this->db
->getFlag( DBO_SYSDBA
) ) {
241 $status->fatal( 'config-db-sys-user-exists-oracle', $this->getVar( 'wgDBuser' ) );
244 if ($status->isOK()) {
245 // user created or already existing, switching back to a normal connection
246 // as the new user has all needed privileges to setup the rest of the schema
247 // i will be using that user as _InstallUser from this point on
250 $this->parent
->setVar( '_InstallUser', $this->getVar( 'wgDBuser' ) );
251 $this->parent
->setVar( '_InstallPassword', $this->getVar( 'wgDBpassword' ) );
252 $this->parent
->setVar( '_InstallDBname', $this->getVar( 'wgDBuser' ) );
253 $status = $this->getConnection();
260 * Overload: after this action field info table has to be rebuilt
263 public function createTables() {
264 $this->setupSchemaVars();
265 $this->db
->setFlag( DBO_DDLMODE
);
266 $this->parent
->setVar( 'wgDBname', $this->getVar( 'wgDBuser' ) );
267 $status = parent
::createTables();
268 $this->db
->clearFlag( DBO_DDLMODE
);
270 $this->db
->query( 'BEGIN fill_wiki_info; END;' );
275 public function getSchemaVars() {
277 # These variables are used by maintenance/oracle/user.sql
283 # These are used by tables.sql
287 foreach ( $varNames as $name ) {
288 $vars[$name] = $this->getVar( $name );
293 public function getLocalSettings() {
294 $prefix = $this->getVar( 'wgDBprefix' );
296 "# Oracle specific settings
297 \$wgDBprefix = \"{$prefix}\";