1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
<?php
/**
* Oracle-specific installer.
*
* @file
* @ingroup Deployment
*/
/**
* Class for setting up the MediaWiki database using Oracle.
*
* @ingroup Deployment
* @since 1.17
*/
class OracleInstaller extends DatabaseInstaller {
protected $globalNames = array(
'wgDBport',
'wgDBname',
'wgDBuser',
'wgDBpassword',
'wgDBprefix',
);
protected $internalDefaults = array(
'_OracleDefTS' => 'USERS',
'_OracleTempTS' => 'TEMP',
'_OracleUseSysdba' => true
);
public function getName() {
return 'oracle';
}
public function isCompiled() {
return self::checkExtension( 'oci8' );
}
public function getWebUserBox( $noCreateMsg = false ) {
$name = $this->getName();
$this->parent->setVar( '_SameAccount', false );
$this->parent->setVar( '_CreateDBAccount', true );
$this->parent->setVar( 'wgDBname', '' );
return Xml::openElement( 'fieldset' ) .
Xml::element( 'legend', array(), wfMsg( 'config-db-web-account' ) ) .
Xml::openElement( 'div', array( 'id' => 'dbOtherAccount' ) ) .
$this->getTextBox( 'wgDBuser', 'config-db-username' ) .
$this->getPasswordBox( 'wgDBpassword', 'config-db-password' ) .
$this->parent->getHelpBox( 'config-db-web-help' ).
$this->getCheckBox( '_CreateDBAccount', 'config-db-web-create', array( 'disabled' => true ) ).
Xml::closeElement( 'div' ) . Xml::closeElement( 'fieldset' );
}
public function getConnectForm() {
$this->parent->setVar( '_InstallUser', 'sys' );
$this->parent->setVar( 'wgDBserver', '' );
return
$this->getTextBox( 'wgDBserver', 'config-db-host-oracle' ) .
$this->parent->getHelpBox( 'config-db-host-oracle-help' ) .
Xml::openElement( 'fieldset' ) .
Xml::element( 'legend', array(), wfMsg( 'config-db-wiki-settings' ) ) .
$this->getTextBox( 'wgDBprefix', 'config-db-prefix' ) .
$this->getTextBox( '_OracleDefTS', 'config-oracle-def-ts' ) .
$this->getTextBox( '_OracleTempTS', 'config-oracle-temp-ts' ) .
$this->parent->getHelpBox( 'config-db-oracle-help' ) .
Xml::closeElement( 'fieldset' ) .
$this->getInstallUserBox().
$this->getWebUserBox();
}
public function submitConnectForm() {
// Get variables from the request
$newValues = $this->setVarsFromRequest( array( 'wgDBserver', 'wgDBprefix', 'wgDBuser', 'wgDBpassword' ) );
$this->parent->setVar( 'wgDBname', $this->getVar( 'wgDBuser' ) );
// Validate them
$status = Status::newGood();
if ( !strlen( $newValues['wgDBserver'] ) ) {
$status->fatal( 'config-missing-db-server-oracle' );
} elseif ( !preg_match( '/^[a-zA-Z0-9_\.]+$/', $newValues['wgDBserver'] ) ) {
$status->fatal( 'config-invalid-db-server-oracle', $newValues['wgDBserver'] );
}
if ( !preg_match( '/^[a-zA-Z0-9_]*$/', $newValues['wgDBprefix'] ) ) {
$status->fatal( 'config-invalid-schema', $newValues['wgDBprefix'] );
}
if ( !$status->isOK() ) {
return $status;
}
// Submit user box
$status = $this->submitInstallUserBox();
if ( !$status->isOK() ) {
return $status;
}
// Try to connect
$status = $this->getConnection();
if ( !$status->isOK() ) {
return $status;
}
$conn = $status->value;
/*
// Check version
$version = $conn->getServerVersion();
if ( version_compare( $version, $this->minimumVersion ) < 0 ) {
return Status::newFatal( 'config-mysql-old', $this->minimumVersion, $version );
}
*/
return $status;
}
public function getConnection() {
$status = Status::newGood();
try {
if ( $this->getVar( '_OracleUseSysdba' ) ) {
$this->db = new DatabaseOracle(
$this->getVar( 'wgDBserver' ),
$this->getVar( '_InstallUser' ),
$this->getVar( '_InstallPassword' ),
$this->getVar( 'wgDBname' ),
false,
DBO_SYSDBA,
$this->getVar( 'wgDBprefix' )
);
} else {
$this->db = new DatabaseOracle(
$this->getVar( 'wgDBserver' ),
$this->getVar( 'wgDBuser' ),
$this->getVar( 'wgDBpassword' ),
$this->getVar( 'wgDBname' ),
false,
0,
$this->getVar( 'wgDBprefix' )
);
}
$status->value = $this->db;
} catch ( DBConnectionError $e ) {
$status->fatal( 'config-connection-error', $e->getMessage() );
}
return $status;
}
public function needsUpgrade() {
$tempDBname = $this->getVar( 'wgDBname' );
$this->parent->setVar( 'wgDBname', $this->getVar( 'wgDBuser' ) );
$retVal = parent::needsUpgrade();
$this->parent->setVar( 'wgDBname', $tempDBname );
return $retVal;
}
public function preInstall() {
# Add our user callback to installSteps, right before the tables are created.
$callback = array(
array(
'name' => 'user',
'callback' => array( $this, 'setupUser' ),
)
);
$this->parent->addInstallStepFollowing( "database", $callback );
}
public function setupDatabase() {
$this->parent->setVar( '_OracleUseSysdba', false );
$status = Status::newGood();
return $status;
}
public function setupUser() {
global $IP;
if ( !$this->getVar( '_CreateDBAccount' ) ) {
return Status::newGood();
}
$status = $this->getConnection();
if ( !$status->isOK() ) {
return $status;
}
global $_OracleDefTS, $_OracleTempTS;
$_OracleDefTS = $this->getVar( '_OracleDefTS' );
$_OracleTempTS = $this->getVar( '_OracleTempTS' );
$error = $this->db->sourceFile( "$IP/maintenance/oracle/user.sql" );
if ( $error !== true || !$this->db->selectDB( $this->getVar( 'wgDBuser' ) ) ) {
$status->fatal( 'config-install-user-failed', $this->getVar( 'wgDBuser' ), $error );
}
return $status;
}
public function getLocalSettings() {
$prefix = $this->getVar( 'wgDBprefix' );
return
"# Oracle specific settings
\$wgDBprefix = \"{$prefix}\";";
}
public function doUpgrade() {
// TODO
return false;
}
}
|