r89807 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89806‎ | r89807 | r89808 >
Date:22:30, 9 June 2011
Author:mah
Status:reverted
Tags:
Comment:
revert r88929
Modified paths:
  • /branches/REL1_17/phase3/includes/installer/DatabaseInstaller.php (modified) (history)
  • /branches/REL1_17/phase3/includes/installer/Installer.i18n.php (modified) (history)
  • /branches/REL1_17/phase3/includes/installer/MysqlInstaller.php (modified) (history)
  • /branches/REL1_17/phase3/includes/installer/OracleInstaller.php (modified) (history)
  • /branches/REL1_17/phase3/includes/installer/PostgresInstaller.php (modified) (history)
  • /branches/REL1_17/phase3/includes/installer/PostgresUpdater.php (modified) (history)
  • /branches/REL1_17/phase3/includes/installer/SqliteInstaller.php (modified) (history)

Diff [purge]

Index: branches/REL1_17/phase3/includes/installer/PostgresUpdater.php
@@ -79,6 +79,7 @@
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' ),
8384 array( 'addPgField', 'mwuser', 'user_newpass_time', 'TIMESTAMPTZ' ),
8485 array( 'addPgField', 'oldimage', 'oi_deleted', 'SMALLINT NOT NULL DEFAULT 0' ),
8586 array( 'addPgField', 'oldimage', 'oi_major_mime', "TEXT NOT NULL DEFAULT 'unknown'" ),
Index: branches/REL1_17/phase3/includes/installer/Installer.i18n.php
@@ -253,7 +253,7 @@
254254 Use only ASCII letters (a-z, A-Z), numbers (0-9), underscores (_) and hyphens (-).',
255255 'config-connection-error' => '$1.
256256
257 -Check the host, username and password and try again.',
 257+Check the host, username and password below and try again.',
258258 'config-invalid-schema' => 'Invalid schema for MediaWiki "$1".
259259 Use only ASCII letters (a-z, A-Z), numbers (0-9) and underscores (_).',
260260 'config-db-sys-create-oracle' => 'Installer only supports using a SYSDBA account for creating a new account.',
Index: branches/REL1_17/phase3/includes/installer/SqliteInstaller.php
@@ -103,7 +103,7 @@
104104 return Status::newGood();
105105 }
106106
107 - public function openConnection( $dbName = null ) {
 107+ public function openConnection() {
108108 global $wgSQLiteDataDir;
109109
110110 $status = Status::newGood();
Index: branches/REL1_17/phase3/includes/installer/DatabaseInstaller.php
@@ -102,7 +102,7 @@
103103 *
104104 * @return Status
105105 */
106 - public abstract function openConnection( $dbName = null );
 106+ public abstract function openConnection();
107107
108108 /**
109109 * Create the database and return a Status object indicating success or
@@ -121,14 +121,11 @@
122122 *
123123 * @return Status
124124 */
125 - public function getConnection( $dbName = null ) {
126 - if ( isset($this->db) && $this->db ) { /* Weirdly get E_STRICT
127 - * errors without the
128 - * isset */
 125+ public function getConnection() {
 126+ if ( $this->db ) {
129127 return Status::newGood( $this->db );
130128 }
131 -
132 - $status = $this->openConnection( $dbName );
 129+ $status = $this->openConnection();
133130 if ( $status->isOK() ) {
134131 $this->db = $status->value;
135132 // Enable autocommit
Index: branches/REL1_17/phase3/includes/installer/MysqlInstaller.php
@@ -111,7 +111,7 @@
112112 return $status;
113113 }
114114
115 - public function openConnection( $dbName = null ) {
 115+ public function openConnection() {
116116 $status = Status::newGood();
117117 try {
118118 $db = new DatabaseMysql(
Index: branches/REL1_17/phase3/includes/installer/OracleInstaller.php
@@ -127,7 +127,7 @@
128128 return $status;
129129 }
130130
131 - public function openConnection( $dbName = null ) {
 131+ public function openConnection() {
132132 $status = Status::newGood();
133133 try {
134134 $db = new DatabaseOracle(
Index: branches/REL1_17/phase3/includes/installer/PostgresInstaller.php
@@ -101,31 +101,22 @@
102102 return $status;
103103 }
104104
105 - public function openConnection( $dbName = null ) {
 105+ public function openConnection() {
106106 $status = Status::newGood();
107107 try {
108108 if ( $this->useAdmin ) {
109 - if ( $dbName === null ) $dbName = 'postgres';
110 -
111109 $db = new DatabasePostgres(
112110 $this->getVar( 'wgDBserver' ),
113111 $this->getVar( '_InstallUser' ),
114112 $this->getVar( '_InstallPassword' ),
115 - $dbName );
 113+ 'postgres' );
116114 } else {
117 - if ( $dbName === null ) $dbName = $this->getVar( 'wgDBname' );
118 -
119115 $db = new DatabasePostgres(
120116 $this->getVar( 'wgDBserver' ),
121117 $this->getVar( 'wgDBuser' ),
122118 $this->getVar( 'wgDBpassword' ),
123 - $dbName );
 119+ $this->getVar( 'wgDBname' ) );
124120 }
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 -
130121 $status->value = $db;
131122 } catch ( DBConnectionError $e ) {
132123 $status->fatal( 'config-connection-error', $e->getMessage() );
@@ -143,15 +134,15 @@
144135
145136 $superuser = $this->getVar( '_InstallUser' );
146137
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__
 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__
153144 );
154145
155 - if( !$rights || $rights == 3 ) {
 146+ if( !$rights || ( $rights != 1 && $rights != 3 ) ) {
156147 return false;
157148 }
158149
@@ -235,12 +226,11 @@
236227 $rows = $conn->numRows( $conn->query( $SQL ) );
237228 $safedb = $conn->addIdentifierQuotes( $dbName );
238229 if( !$rows ) {
239 - $conn->query( "CREATE DATABASE $safedb", __METHOD__ );
240 - $conn->query( "GRANT ALL ON DATABASE $safedb to $safeuser", __METHOD__ );
 230+ $conn->query( "CREATE DATABASE $safedb OWNER $safeuser", __METHOD__ );
241231 } else {
242 - $conn->query( "GRANT ALL ON DATABASE $safedb TO $safeuser", __METHOD__ );
 232+ $conn->query( "ALTER DATABASE $safedb OWNER TO $safeuser", __METHOD__ );
243233 }
244 -
 234+
245235 // Now that we've established the real database exists, connect to it
246236 // Because we do not want the same connection, forcibly expire the existing conn
247237 $this->db = null;
@@ -297,18 +287,17 @@
298288 $safeschema = $this->db->addIdentifierQuotes( $schema );
299289
300290 $rows = $this->db->numRows(
301 - $this->db->query( "SELECT 1 FROM pg_catalog.pg_roles WHERE rolname = $safeusercheck" )
 291+ $this->db->query( "SELECT 1 FROM pg_catalog.pg_shadow WHERE usename = $safeusercheck" )
302292 );
303293 if ( $rows < 1 ) {
304 - $res = $this->db->query( "CREATE ROLE $safeuser NOCREATEDB LOGIN PASSWORD $safepass", __METHOD__ );
 294+ $res = $this->db->query( "CREATE USER $safeuser NOCREATEDB PASSWORD $safepass", __METHOD__ );
305295 if ( $res !== true && !( $res instanceOf ResultWrapper ) ) {
306296 $status->fatal( 'config-install-user-failed', $this->getVar( 'wgDBuser' ), $res );
307297 }
308298 if( $status->isOK() ) {
309 - $this->db->query("ALTER ROLE $safeuser LOGIN");
 299+ $this->db->query("ALTER USER $safeuser SET search_path = $safeschema");
310300 }
311301 }
312 - $this->db->query("ALTER ROLE $safeuser SET search_path = $safeschema, public");
313302
314303 return $status;
315304 }
@@ -348,11 +337,12 @@
349338
350339 $this->db->begin( __METHOD__ );
351340
352 - // getConnection() should have already selected the schema if it exists
353341 if( !$this->db->schemaExists( $schema ) ) {
354342 $status->error( 'config-install-pg-schema-not-exist' );
355343 return $status;
356344 }
 345+ $safeschema = $this->db->addIdentifierQuotes( $schema );
 346+ $this->db->query( "SET search_path = $safeschema" );
357347 $error = $this->db->sourceFile( $this->db->getSchema() );
358348 if( $error !== true ) {
359349 $this->db->reportQueryError( $error, 0, '', __METHOD__ );
@@ -369,18 +359,12 @@
370360 }
371361
372362 public function setupPLpgSQL() {
373 - $this->db = null;
374363 $this->useAdmin = true;
375 - $dbName = $this->getVar( 'wgDBname' );
376 - $status = $this->getConnection( $dbName );
 364+ $status = $this->getConnection();
377365 if ( !$status->isOK() ) {
378366 return $status;
379367 }
380 - $this->db = $status->value;
381368
382 - /* Admin user has to be connected to the db it just
383 - created to satisfy ownership requirements for
384 - "CREATE LANGAUGE" */
385369 $rows = $this->db->numRows(
386370 $this->db->query( "SELECT 1 FROM pg_catalog.pg_language WHERE lanname = 'plpgsql'" )
387371 );
@@ -389,6 +373,7 @@
390374 $SQL = "SELECT 1 FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON (n.oid = c.relnamespace) ".
391375 "WHERE relname = 'pg_pltemplate' AND nspname='pg_catalog'";
392376 $rows = $this->db->numRows( $this->db->query( $SQL ) );
 377+ $dbName = $this->getVar( 'wgDBname' );
393378 if ( $rows >= 1 ) {
394379 $result = $this->db->query( 'CREATE LANGUAGE plpgsql' );
395380 if ( !$result ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r89822Revert r89807, i.e. reapply r88929, since it has some useful changes and is t...tstarling11:55, 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