@ -> wfSuppressWarnings and wfRestoreWarnings
[lhc/web/wiklou.git] / includes / installer / PostgresInstaller.php
1 <?php
2
3 class PostgresInstaller extends DatabaseInstaller {
4
5 protected $globalNames = array(
6 'wgDBserver',
7 'wgDBport',
8 'wgDBname',
9 'wgDBuser',
10 'wgDBpassword',
11 'wgDBmwschema',
12 'wgDBts2schema',
13 );
14
15 protected $internalDefaults = array(
16 '_InstallUser' => 'postgres',
17 '_InstallPassword' => '',
18 );
19
20 var $minimumVersion = '8.1';
21
22 var $conn;
23
24 function getName() {
25 return 'postgres';
26 }
27
28 public function isCompiled() {
29 return self::checkExtension( 'pgsql' );
30 }
31
32 function getConnectForm() {
33 return
34 $this->getTextBox( 'wgDBserver', 'config-db-host' ) .
35 $this->parent->getHelpBox( 'config-db-host-help' ) .
36 $this->getTextBox( 'wgDBport', 'config-db-port' ) .
37 Xml::openElement( 'fieldset' ) .
38 Xml::element( 'legend', array(), wfMsg( 'config-db-wiki-settings' ) ) .
39 $this->getTextBox( 'wgDBname', 'config-db-name' ) .
40 $this->parent->getHelpBox( 'config-db-name-help' ) .
41 $this->getTextBox( 'wgDBmwschema', 'config-db-schema' ) .
42 $this->getTextBox( 'wgDBts2schema', 'config-db-ts2-schema' ) .
43 $this->parent->getHelpBox( 'config-db-schema-help' ) .
44 Xml::closeElement( 'fieldset' ) .
45 $this->getInstallUserBox();
46 }
47
48 function submitConnectForm() {
49 // Get variables from the request
50 $newValues = $this->setVarsFromRequest( array( 'wgDBserver', 'wgDBport',
51 'wgDBname', 'wgDBmwschema', 'wgDBts2schema' ) );
52
53 // Validate them
54 $status = Status::newGood();
55 if ( !strlen( $newValues['wgDBname'] ) ) {
56 $status->fatal( 'config-missing-db-name' );
57 } elseif ( !preg_match( '/^[a-zA-Z0-9_]+$/', $newValues['wgDBname'] ) ) {
58 $status->fatal( 'config-invalid-db-name', $newValues['wgDBname'] );
59 }
60 if ( !preg_match( '/^[a-zA-Z0-9_]*$/', $newValues['wgDBmwschema'] ) ) {
61 $status->fatal( 'config-invalid-schema', $newValues['wgDBmwschema'] );
62 }
63 if ( !preg_match( '/^[a-zA-Z0-9_]*$/', $newValues['wgDBts2schema'] ) ) {
64 $status->fatal( 'config-invalid-ts2schema', $newValues['wgDBts2schema'] );
65 }
66
67 // Submit user box
68 if ( $status->isOK() ) {
69 $status->merge( $this->submitInstallUserBox() );
70 }
71 if ( !$status->isOK() ) {
72 return $status;
73 }
74
75 // Try to connect
76 if ( $status->isOK() ) {
77 $status->merge( $this->attemptConnection() );
78 }
79 if ( !$status->isOK() ) {
80 return $status;
81 }
82
83 // Check version
84 $version = $this->conn->getServerVersion();
85 if ( version_compare( $version, $this->minimumVersion ) < 0 ) {
86 return Status::newFatal( 'config-postgres-old', $this->minimumVersion, $version );
87 }
88 return $status;
89 }
90
91 function attemptConnection() {
92 $status = Status::newGood();
93
94 try {
95 $this->conn = new DatabasePostgres(
96 $this->getVar( 'wgDBserver' ),
97 $this->getVar( '_InstallUser' ),
98 $this->getVar( '_InstallPassword' ),
99 'postgres' );
100 $status->value = $this->conn;
101 } catch ( DBConnectionError $e ) {
102 $status->fatal( 'config-connection-error', $e->getMessage() );
103 }
104 return $status;
105 }
106
107 function getConnection() {
108 return $this->attemptConnection();
109 }
110
111 function getSettingsForm() {
112 return false;
113 }
114
115 function submitSettingsForm() {
116 return Status::newGood();
117 }
118
119 function setupDatabase() {
120 }
121
122 function createTables() {
123 }
124
125 function getLocalSettings() {
126 $port = $this->getVar( 'wgDBport' );
127 $schema = $this->getVar( 'wgDBmwschema' );
128 $ts2 = $this->getVar( 'wgDBts2schema' );
129 return
130 "# Postgres specific settings
131 \$wgDBport = \"{$port}\";
132 \$wgDBmwschema = \"{$schema}\";
133 \$wgDBts2schema = \"{$ts2}\";";
134 }
135 }