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