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