r89389 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89388‎ | r89389 | r89390 >
Date:03:41, 3 June 2011
Author:mah
Status:resolved
Tags:
Comment:
forward port r88929
Modified paths:
  • /trunk/phase3/includes/installer/DatabaseInstaller.php (modified) (history)
  • /trunk/phase3/includes/installer/Ibm_db2Installer.php (modified) (history)
  • /trunk/phase3/includes/installer/Installer.i18n.php (modified) (history)
  • /trunk/phase3/includes/installer/MysqlInstaller.php (modified) (history)
  • /trunk/phase3/includes/installer/OracleInstaller.php (modified) (history)
  • /trunk/phase3/includes/installer/PostgresInstaller.php (modified) (history)
  • /trunk/phase3/includes/installer/PostgresUpdater.php (modified) (history)
  • /trunk/phase3/includes/installer/SqliteInstaller.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/installer/PostgresUpdater.php
@@ -79,7 +79,6 @@
8080 array( 'addPgField', 'logging', 'log_id', "INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('logging_log_id_seq')" ),
8181 array( 'addPgField', 'logging', 'log_params', 'TEXT' ),
8282 array( 'addPgField', 'mwuser', 'user_editcount', 'INTEGER' ),
83 - array( 'addPgField', 'mwuser', 'user_hidden', 'SMALLINT NOT NULL DEFAULT 0' ),
8483 array( 'addPgField', 'mwuser', 'user_newpass_time', 'TIMESTAMPTZ' ),
8584 array( 'addPgField', 'oldimage', 'oi_deleted', 'SMALLINT NOT NULL DEFAULT 0' ),
8685 array( 'addPgField', 'oldimage', 'oi_major_mime', "TEXT NOT NULL DEFAULT 'unknown'" ),
Index: trunk/phase3/includes/installer/Installer.i18n.php
@@ -256,7 +256,7 @@
257257 Use only ASCII letters (a-z, A-Z), numbers (0-9), underscores (_) and hyphens (-).',
258258 'config-connection-error' => '$1.
259259
260 -Check the host, username and password below and try again.',
 260+Check the host, username and password and try again.',
261261 'config-invalid-schema' => 'Invalid schema for MediaWiki "$1".
262262 Use only ASCII letters (a-z, A-Z), numbers (0-9) and underscores (_).',
263263 'config-db-sys-create-oracle' => 'Installer only supports using a SYSDBA account for creating a new account.',
Index: trunk/phase3/includes/installer/Ibm_db2Installer.php
@@ -113,7 +113,7 @@
114114 * Open a DB2 database connection
115115 * @return Status
116116 */
117 - public function openConnection() {
 117+ public function openConnection( $dbName = null ) {
118118 $status = Status::newGood();
119119 try {
120120 $db = new DatabaseIbm_db2(
Index: trunk/phase3/includes/installer/SqliteInstaller.php
@@ -122,7 +122,7 @@
123123 /**
124124 * @return Status
125125 */
126 - public function openConnection() {
 126+ public function openConnection( $dbName = null ) {
127127 global $wgSQLiteDataDir;
128128
129129 $status = Status::newGood();
Index: trunk/phase3/includes/installer/DatabaseInstaller.php
@@ -102,7 +102,7 @@
103103 *
104104 * @return Status
105105 */
106 - public abstract function openConnection();
 106+ public abstract function openConnection( $dbName = null );
107107
108108 /**
109109 * Create the database and return a Status object indicating success or
@@ -121,11 +121,14 @@
122122 *
123123 * @return Status
124124 */
125 - public function getConnection() {
126 - if ( $this->db ) {
 125+ public function getConnection( $dbName = null ) {
 126+ if ( isset($this->db) && $this->db ) { /* Weirdly get E_STRICT
 127+ * errors without the
 128+ * isset */
127129 return Status::newGood( $this->db );
128130 }
129 - $status = $this->openConnection();
 131+
 132+ $status = $this->openConnection( $dbName );
130133 if ( $status->isOK() ) {
131134 $this->db = $status->value;
132135 // Enable autocommit
Index: trunk/phase3/includes/installer/MysqlInstaller.php
@@ -126,7 +126,7 @@
127127 /**
128128 * @return Status
129129 */
130 - public function openConnection() {
 130+ public function openConnection( $dbName = null ) {
131131 $status = Status::newGood();
132132 try {
133133 $db = new DatabaseMysql(
Index: trunk/phase3/includes/installer/OracleInstaller.php
@@ -127,7 +127,7 @@
128128 return $status;
129129 }
130130
131 - public function openConnection() {
 131+ public function openConnection( $dbName = null ) {
132132 $status = Status::newGood();
133133 try {
134134 $db = new DatabaseOracle(
Index: trunk/phase3/includes/installer/PostgresInstaller.php
@@ -101,22 +101,31 @@
102102 return $status;
103103 }
104104
105 - public function openConnection() {
 105+ public function openConnection( $dbName = null ) {
106106 $status = Status::newGood();
107107 try {
108108 if ( $this->useAdmin ) {
 109+ if ( $dbName === null ) $dbName = 'postgres';
 110+
109111 $db = new DatabasePostgres(
110112 $this->getVar( 'wgDBserver' ),
111113 $this->getVar( '_InstallUser' ),
112114 $this->getVar( '_InstallPassword' ),
113 - 'postgres' );
 115+ $dbName );
114116 } else {
 117+ if ( $dbName === null ) $dbName = $this->getVar( 'wgDBname' );
 118+
115119 $db = new DatabasePostgres(
116120 $this->getVar( 'wgDBserver' ),
117121 $this->getVar( 'wgDBuser' ),
118122 $this->getVar( 'wgDBpassword' ),
119 - $this->getVar( 'wgDBname' ) );
 123+ $dbName );
120124 }
 125+
 126+ if( $db === null ) throw new DBConnectionError("Unknown problem while connecting.");
 127+ $safeschema = $db->addIdentifierQuotes( $this->getVar( 'wgDBmwschema' ) );
 128+ if( $db->schemaExists( $this->getVar( 'wgDBmwschema' ) ) ) $db->query( "SET search_path = $safeschema" );
 129+
121130 $status->value = $db;
122131 } catch ( DBConnectionError $e ) {
123132 $status->fatal( 'config-connection-error', $e->getMessage() );
@@ -134,15 +143,15 @@
135144
136145 $superuser = $this->getVar( '_InstallUser' );
137146
138 - $rights = $conn->selectField( 'pg_catalog.pg_user',
139 - 'CASE WHEN usesuper IS TRUE THEN
140 - CASE WHEN usecreatedb IS TRUE THEN 3 ELSE 1 END
141 - ELSE CASE WHEN usecreatedb IS TRUE THEN 2 ELSE 0 END
142 - END AS rights',
143 - array( 'usename' => $superuser ), __METHOD__
 147+ $rights = $conn->selectField( 'pg_catalog.pg_roles',
 148+ 'CASE WHEN rolsuper then 1
 149+ WHEN rolcreatedb then 2
 150+ ELSE 3
 151+ END as rights',
 152+ array( 'rolname' => $superuser ), __METHOD__
144153 );
145154
146 - if( !$rights || ( $rights != 1 && $rights != 3 ) ) {
 155+ if( !$rights || $rights == 3 ) {
147156 return false;
148157 }
149158
@@ -226,9 +235,10 @@
227236 $rows = $conn->numRows( $conn->query( $SQL ) );
228237 $safedb = $conn->addIdentifierQuotes( $dbName );
229238 if( !$rows ) {
230 - $conn->query( "CREATE DATABASE $safedb OWNER $safeuser", __METHOD__ );
 239+ $conn->query( "CREATE DATABASE $safedb", __METHOD__ );
 240+ $conn->query( "GRANT ALL ON DATABASE $safedb to $safeuser", __METHOD__ );
231241 } else {
232 - $conn->query( "ALTER DATABASE $safedb OWNER TO $safeuser", __METHOD__ );
 242+ $conn->query( "GRANT ALL ON DATABASE $safedb TO $safeuser", __METHOD__ );
233243 }
234244
235245 // Now that we've established the real database exists, connect to it
@@ -287,17 +297,18 @@
288298 $safeschema = $this->db->addIdentifierQuotes( $schema );
289299
290300 $rows = $this->db->numRows(
291 - $this->db->query( "SELECT 1 FROM pg_catalog.pg_shadow WHERE usename = $safeusercheck" )
 301+ $this->db->query( "SELECT 1 FROM pg_catalog.pg_roles WHERE rolname = $safeusercheck" )
292302 );
293303 if ( $rows < 1 ) {
294 - $res = $this->db->query( "CREATE USER $safeuser NOCREATEDB PASSWORD $safepass", __METHOD__ );
 304+ $res = $this->db->query( "CREATE ROLE $safeuser NOCREATEDB LOGIN PASSWORD $safepass", __METHOD__ );
295305 if ( $res !== true && !( $res instanceOf ResultWrapper ) ) {
296306 $status->fatal( 'config-install-user-failed', $this->getVar( 'wgDBuser' ), $res );
297307 }
298308 if( $status->isOK() ) {
299 - $this->db->query("ALTER USER $safeuser SET search_path = $safeschema");
 309+ $this->db->query("ALTER ROLE $safeuser LOGIN");
300310 }
301311 }
 312+ $this->db->query("ALTER ROLE $safeuser SET search_path = $safeschema, public");
302313
303314 return $status;
304315 }
@@ -337,12 +348,11 @@
338349
339350 $this->db->begin( __METHOD__ );
340351
 352+ // getConnection() should have already selected the schema if it exists
341353 if( !$this->db->schemaExists( $schema ) ) {
342354 $status->error( 'config-install-pg-schema-not-exist' );
343355 return $status;
344356 }
345 - $safeschema = $this->db->addIdentifierQuotes( $schema );
346 - $this->db->query( "SET search_path = $safeschema" );
347357 $error = $this->db->sourceFile( $this->db->getSchema() );
348358 if( $error !== true ) {
349359 $this->db->reportQueryError( $error, 0, '', __METHOD__ );
@@ -359,12 +369,18 @@
360370 }
361371
362372 public function setupPLpgSQL() {
 373+ $this->db = null;
363374 $this->useAdmin = true;
364 - $status = $this->getConnection();
 375+ $dbName = $this->getVar( 'wgDBname' );
 376+ $status = $this->getConnection( $dbName );
365377 if ( !$status->isOK() ) {
366378 return $status;
367379 }
 380+ $this->db = $status->value;
368381
 382+ /* Admin user has to be connected to the db it just
 383+ created to satisfy ownership requirements for
 384+ "CREATE LANGAUGE" */
369385 $rows = $this->db->numRows(
370386 $this->db->query( "SELECT 1 FROM pg_catalog.pg_language WHERE lanname = 'plpgsql'" )
371387 );
@@ -373,7 +389,6 @@
374390 $SQL = "SELECT 1 FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON (n.oid = c.relnamespace) ".
375391 "WHERE relname = 'pg_pltemplate' AND nspname='pg_catalog'";
376392 $rows = $this->db->numRows( $this->db->query( $SQL ) );
377 - $dbName = $this->getVar( 'wgDBname' );
378393 if ( $rows >= 1 ) {
379394 $result = $this->db->query( 'CREATE LANGUAGE plpgsql' );
380395 if ( !$result ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r89821PostgreSQL install fixes:...tstarling11:32, 10 June 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r88929Commiting here, because other problems exist on trunk. This needs to...mah20:34, 26 May 2011

Status & tagging log