Add getConnection() for Oracle
[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 '_InstallUser' => 'sys',
27 '_InstallPassword' => '',
28 );
29
30 public function getName() {
31 return 'oracle';
32 }
33
34 public function isCompiled() {
35 return self::checkExtension( 'oci8' );
36 }
37
38 public function getConnectForm() {
39 return
40 Xml::openElement( 'fieldset' ) .
41 Xml::element( 'legend', array(), wfMsg( 'config-db-wiki-settings' ) ) .
42 $this->getTextBox( 'wgDBname', 'config-db-name' ) .
43 $this->parent->getHelpBox( 'config-db-name-help' ) .
44 $this->getTextBox( 'wgDBprefix', 'config-db-prefix' ) .
45 $this->parent->getHelpBox( 'config-db-prefix-help' ) .
46 Xml::closeElement( 'fieldset' ) .
47 $this->getInstallUserBox();
48 }
49
50 public function submitConnectForm() {
51 // Get variables from the request
52 $newValues = $this->setVarsFromRequest( array( 'wgDBname', 'wgDBprefix' ) );
53
54 // Validate them
55 $status = Status::newGood();
56 if ( !strlen( $newValues['wgDBname'] ) ) {
57 $status->fatal( 'config-missing-db-name' );
58 } elseif ( !preg_match( '/^[a-zA-Z0-9_]+$/', $newValues['wgDBname'] ) ) {
59 $status->fatal( 'config-invalid-db-name', $newValues['wgDBname'] );
60 }
61 if ( !preg_match( '/^[a-zA-Z0-9_]*$/', $newValues['wgDBprefix'] ) ) {
62 $status->fatal( 'config-invalid-schema', $newValues['wgDBprefix'] );
63 }
64
65 // Submit user box
66 if ( $status->isOK() ) {
67 $status->merge( $this->submitInstallUserBox() );
68 }
69 if ( !$status->isOK() ) {
70 return $status;
71 }
72
73 // Try to connect
74 if ( $status->isOK() ) {
75 $status->merge( $this->attemptConnection() );
76 }
77 if ( !$status->isOK() ) {
78 return $status;
79 }
80
81 // Check version
82 /*
83 $version = $this->conn->getServerVersion();
84 if ( version_compare( $version, $this->minimumVersion ) < 0 ) {
85 return Status::newFatal( 'config-postgres-old', $this->minimumVersion, $version );
86 }
87 */
88 return $status;
89 }
90
91 public function getConnection() {
92 $status = Status::newGood();
93 try {
94 $this->db = new DatabaseOracle(
95 $this->getVar( 'wgDBserver' ),
96 $this->getVar( '_InstallUser' ),
97 $this->getVar( '_InstallPassword' ),
98 false,
99 false,
100 0,
101 $this->getVar( 'wgDBprefix' )
102 );
103 $status->value = $this->db;
104 } catch ( DBConnectionError $e ) {
105 $status->fatal( 'config-connection-error', $e->getMessage() );
106 }
107 return $status;
108 }
109
110 public function setupDatabase() {
111 // TODO
112 }
113
114 public function getLocalSettings() {
115 $prefix = $this->getVar( 'wgDBprefix' );
116 return
117 "# Oracle specific settings
118 \$wgDBprefix = \"{$prefix}\";";
119 }
120
121 public function doUpgrade() {
122 // TODO
123 return false;
124 }
125 }