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