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