Index: trunk/phase3/includes/installer/Installer.i18n.php |
— | — | @@ -452,6 +452,9 @@ |
453 | 453 | Make sure that the user "$1" can write to the schema "$2".', |
454 | 454 | 'config-install-pg-commit' => 'Committing changes', |
455 | 455 | 'config-pg-no-plpgsql' => 'You need to install the language PL/pgSQL in the database $1', |
| 456 | + 'config-install-pg-ts2' => 'Checking for tsearch2', |
| 457 | + 'config-install-pg-ts2-failed' => "'''FAILED''' tsearch2 must be installed in the database $1 |
| 458 | +Please read [http://www.devx.com/opensource/Article/21674/0/page/2 these instructions] or ask on #postgresql on irc.freenode.net</li>\n", |
456 | 459 | 'config-install-user' => 'Creating database user', |
457 | 460 | 'config-install-user-failed' => 'Granting permission to user "$1" failed: $2', |
458 | 461 | 'config-install-tables' => 'Creating tables', |
Index: trunk/phase3/includes/installer/MysqlInstaller.php |
— | — | @@ -410,7 +410,7 @@ |
411 | 411 | $conn = $status->value; |
412 | 412 | $dbName = $this->getVar( 'wgDBname' ); |
413 | 413 | if( !$conn->selectDB( $dbName ) ) { |
414 | | - $conn->query( "CREATE DATABASE `$dbName`", __METHOD__ ); |
| 414 | + $conn->query( "CREATE DATABASE " . $conn->addIdentifierQuotes( $dbName ), __METHOD__ ); |
415 | 415 | $conn->selectDB( $dbName ); |
416 | 416 | } |
417 | 417 | return $status; |
Index: trunk/phase3/includes/installer/PostgresInstaller.php |
— | — | @@ -25,6 +25,7 @@ |
26 | 26 | ); |
27 | 27 | |
28 | 28 | var $minimumVersion = '8.1'; |
| 29 | + private $ts2MaxVersion = '8.3'; // Doing ts2 is not necessary in PG > 8.3 |
29 | 30 | |
30 | 31 | function getName() { |
31 | 32 | return 'postgres'; |
— | — | @@ -99,7 +100,7 @@ |
100 | 101 | $this->getVar( 'wgDBserver' ), |
101 | 102 | $this->getVar( '_InstallUser' ), |
102 | 103 | $this->getVar( '_InstallPassword' ), |
103 | | - $this->getVar( 'wgDBname' ) ); |
| 104 | + false ); |
104 | 105 | $status->value = $this->db; |
105 | 106 | } catch ( DBConnectionError $e ) { |
106 | 107 | $status->fatal( 'config-connection-error', $e->getMessage() ); |
— | — | @@ -107,13 +108,50 @@ |
108 | 109 | return $status; |
109 | 110 | } |
110 | 111 | |
| 112 | + protected function canCreateAccounts() { |
| 113 | + $status = $this->getConnection(); |
| 114 | + if ( !$status->isOK() ) { |
| 115 | + return false; |
| 116 | + } |
| 117 | + $conn = $status->value; |
| 118 | + |
| 119 | + $superuser = $this->getVar( '_InstallUser' ); |
| 120 | + |
| 121 | + $rights = $conn->query( 'pg_catalog.pg_user', |
| 122 | + 'SELECT |
| 123 | + CASE WHEN usesuper IS TRUE THEN |
| 124 | + CASE WHEN usecreatedb IS TRUE THEN 3 ELSE 1 END |
| 125 | + ELSE CASE WHEN usecreatedb IS TRUE THEN 2 ELSE 0 END |
| 126 | + END AS rights', |
| 127 | + array( 'usename' => $superuser ), __METHOD__ |
| 128 | + ); |
| 129 | + |
| 130 | + if( !$rights ) { |
| 131 | + return false; |
| 132 | + } |
| 133 | + |
| 134 | + if( $rights != 1 && $rights != 3 ) { |
| 135 | + return false; |
| 136 | + } |
| 137 | + |
| 138 | + return true; |
| 139 | + } |
| 140 | + |
111 | 141 | public function preInstall() { |
112 | | - # Add our user callback to installSteps, right before the tables are created. |
113 | | - $callback = array( |
| 142 | + $commitCB = array( |
114 | 143 | 'name' => 'pg-commit', |
115 | 144 | 'callback' => array( $this, 'commitChanges' ), |
116 | 145 | ); |
117 | | - $this->parent->addInstallStep( $callback, 'interwiki' ); |
| 146 | + $userCB = array( |
| 147 | + 'name' => 'user', |
| 148 | + 'callback' => array( $this, 'setupUser' ), |
| 149 | + ); |
| 150 | + $ts2CB = array( |
| 151 | + 'name' => 'pg-ts2', |
| 152 | + 'callback' => array( $this, 'setupTs2' ), |
| 153 | + ); |
| 154 | + $this->parent->addInstallStep( $commitCB, 'interwiki' ); |
| 155 | + $this->parent->addInstallStep( $userCB ); |
118 | 156 | } |
119 | 157 | |
120 | 158 | function setupDatabase() { |
— | — | @@ -137,16 +175,65 @@ |
138 | 176 | $this->getVar( 'wgDBuser'), $schema ); |
139 | 177 | } |
140 | 178 | $conn->query( "DROP TABLE $safeschema.$ctest" ); |
141 | | - |
| 179 | + |
| 180 | + $dbName = $this->getVar( 'wgDBname' ); |
| 181 | + if( !$conn->selectDB( $dbName ) ) { |
| 182 | + $safedb = $conn->addIdentifierQuotes( $dbName ); |
| 183 | + $safeuser = $conn->addQuotes( $this->getVar( 'wgDBuser' ) ); |
| 184 | + $conn->query( "CREATE DATABASE $safedb OWNER $safeuser", __METHOD__ ); |
| 185 | + $conn->selectDB( $dbName ); |
| 186 | + } |
142 | 187 | return $status; |
143 | 188 | } |
144 | 189 | |
| 190 | + /** |
| 191 | + * Ts2 isn't needed in newer versions of Postgres, so wrap it in a nice big |
| 192 | + * version check and skip it if we're new. Maybe we can bump $minimumVersion |
| 193 | + * one day and render this obsolete :) |
| 194 | + * |
| 195 | + * @return Status |
| 196 | + */ |
| 197 | + function setupTs2() { |
| 198 | + if( version_compare( $this->db->getServerVersion(), $this->ts2MaxVersion, '<' ) ) { |
| 199 | + if ( !$this->db->tableExists( 'pg_ts_cfg', $wgDBts2schema ) ) { |
| 200 | + return Status::newFatal( 'config-install-pg-ts2-failed' ); |
| 201 | + } |
| 202 | + $safeuser = $this->db->addQuotes( $this->getVar( 'wgDBuser' ) ); |
| 203 | + foreach ( array( 'cfg', 'cfgmap', 'dict', 'parser' ) as $table ) { |
| 204 | + $sql = "GRANT SELECT ON pg_ts_$table TO $safeuser"; |
| 205 | + $this->db->query( $sql, __METHOD__ ); |
| 206 | + } |
| 207 | + } |
| 208 | + return Status::newGood(); |
| 209 | + } |
| 210 | + |
145 | 211 | function commitChanges() { |
146 | 212 | $this->db->query( 'COMMIT' ); |
147 | | - |
148 | 213 | return Status::newGood(); |
149 | 214 | } |
150 | 215 | |
| 216 | + function setupUser() { |
| 217 | + if ( !$this->getVar( '_CreateDBAccount' ) ) { |
| 218 | + return Status::newGood(); |
| 219 | + } |
| 220 | + |
| 221 | + $status = $this->getConnection(); |
| 222 | + if ( !$status->isOK() ) { |
| 223 | + return $status; |
| 224 | + } |
| 225 | + |
| 226 | + $db = $this->getVar( 'wgDBname' ); |
| 227 | + $this->db->selectDB( $db ); |
| 228 | + $safeuser = $this->db->addQuotes( $this->getVar( 'wgDBuser' ) ); |
| 229 | + $safepass = $this->db->addQuotes( $this->getVar( 'wgDBpassword' ) ); |
| 230 | + $res = $this->db->query( "CREATE USER $safeuser NOCREATEDB PASSWORD $safepass", __METHOD__ ); |
| 231 | + if ( $res !== true ) { |
| 232 | + $status->fatal( 'config-install-user-failed', $this->getVar( 'wgDBuser' ) ); |
| 233 | + } |
| 234 | + |
| 235 | + return $status; |
| 236 | + } |
| 237 | + |
151 | 238 | function getLocalSettings() { |
152 | 239 | $port = $this->getVar( 'wgDBport' ); |
153 | 240 | $schema = $this->getVar( 'wgDBmwschema' ); |