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