* Installer for Oracle fixes
[mediawiki.git] / includes / installer / PostgresInstaller.php
blobc0d967727ff68badec0483e7a7420f42f4dd1587
1 <?php
2 /**
3 * PostgreSQL-specific installer.
5 * @file
6 * @ingroup Deployment
7 */
9 /**
10 * Class for setting up the MediaWiki database using Postgres.
12 * @ingroup Deployment
13 * @since 1.17
15 class PostgresInstaller extends DatabaseInstaller {
17 protected $globalNames = array(
18 'wgDBserver',
19 'wgDBport',
20 'wgDBname',
21 'wgDBuser',
22 'wgDBpassword',
23 'wgDBmwschema',
24 'wgDBts2schema',
27 var $minimumVersion = '8.1';
29 function getName() {
30 return 'postgres';
33 public function isCompiled() {
34 return self::checkExtension( 'pgsql' );
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();
53 function submitConnectForm() {
54 // Get variables from the request
55 $newValues = $this->setVarsFromRequest( array( 'wgDBserver', 'wgDBport',
56 'wgDBname', 'wgDBmwschema', 'wgDBts2schema' ) );
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'] );
65 if ( !preg_match( '/^[a-zA-Z0-9_]*$/', $newValues['wgDBmwschema'] ) ) {
66 $status->fatal( 'config-invalid-schema', $newValues['wgDBmwschema'] );
68 if ( !preg_match( '/^[a-zA-Z0-9_]*$/', $newValues['wgDBts2schema'] ) ) {
69 $status->fatal( 'config-invalid-ts2schema', $newValues['wgDBts2schema'] );
72 // Submit user box
73 if ( $status->isOK() ) {
74 $status->merge( $this->submitInstallUserBox() );
76 if ( !$status->isOK() ) {
77 return $status;
80 // Try to connect
81 $status->merge( $this->getConnection() );
82 if ( !$status->isOK() ) {
83 return $status;
86 // Check version
87 $version = $this->db->getServerVersion();
88 if ( version_compare( $version, $this->minimumVersion ) < 0 ) {
89 return Status::newFatal( 'config-postgres-old', $this->minimumVersion, $version );
92 $this->setVar( 'wgDBuser', $this->getVar( '_InstallUser' ) );
93 $this->setVar( 'wgDBpassword', $this->getVar( '_InstallPassword' ) );
94 return $status;
97 function getConnection() {
98 $status = Status::newGood();
100 try {
101 $this->db = new DatabasePostgres(
102 $this->getVar( 'wgDBserver' ),
103 $this->getVar( '_InstallUser' ),
104 $this->getVar( '_InstallPassword' ),
105 $this->getVar( 'wgDBname' ) );
106 $status->value = $this->db;
107 } catch ( DBConnectionError $e ) {
108 $status->fatal( 'config-connection-error', $e->getMessage() );
110 return $status;
113 function setupDatabase() {
116 function getLocalSettings() {
117 $port = $this->getVar( 'wgDBport' );
118 $schema = $this->getVar( 'wgDBmwschema' );
119 $ts2 = $this->getVar( 'wgDBts2schema' );
120 return
121 "# Postgres specific settings
122 \$wgDBport = \"{$port}\";
123 \$wgDBmwschema = \"{$schema}\";
124 \$wgDBts2schema = \"{$ts2}\";";
127 public function preUpgrade() {
128 global $wgDBuser, $wgDBpassword;
130 # Normal user and password are selected after this step, so for now
131 # just copy these two
132 $wgDBuser = $this->getVar( '_InstallUser' );
133 $wgDBpassword = $this->getVar( '_InstallPassword' );