From 2289db61578cc4ade0e828d8d52654302bca0d3d Mon Sep 17 00:00:00 2001 From: Greg Sabino Mullane Date: Wed, 16 May 2007 20:21:27 +0000 Subject: [PATCH] Check that the user is configured correctly if using Postgres --- maintenance/updaters.inc | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/maintenance/updaters.inc b/maintenance/updaters.inc index 4707891dfe..e46ec69b9a 100644 --- a/maintenance/updaters.inc +++ b/maintenance/updaters.inc @@ -1160,7 +1160,7 @@ END; } function do_postgres_updates() { - global $wgDatabase, $wgVersion, $wgDBmwschema, $wgShowExceptionDetails; + global $wgDatabase, $wgVersion, $wgDBmwschema, $wgDBts2schema, $wgShowExceptionDetails, $wgDBuser; $wgShowExceptionDetails = 1; @@ -1168,6 +1168,41 @@ function do_postgres_updates() { if ( !isset( $wgDBmwschema )) $wgDBmwschema = 'mediawiki'; + # Verify that this user is configured correctly + $safeuser = $wgDatabase->addQuotes($wgDBuser); + $SQL = "SELECT array_to_string(useconfig,'*') FROM pg_user WHERE usename = $safeuser"; + $config = pg_fetch_result( $wgDatabase->doQuery( $SQL ), 0, 0 ); + $conf = array(); + foreach( explode( '*', $config ) as $c ) { + list( $x,$y ) = explode( '=', $c ); + $conf[$x] = $y; + } + $newpath = array(); + if( !array_key_exists( 'search_path', $conf ) or strpos( $conf['search_path'],$wgDBmwschema ) === false ) { + print "Adding in schema \"$wgDBmwschema\" to search_path for user \"$wgDBuser\"\n"; + $newpath[$wgDBmwschema] = 1; + } + if( !array_key_exists( 'search_path', $conf ) or strpos( $conf['search_path'],$wgDBts2schema ) === false ) { + print "Adding in schema \"$wgDBts2schema\" to search_path for user \"$wgDBuser\"\n"; + $newpath[$wgDBts2schema] = 1; + } + $searchpath = implode( ',', array_keys( $newpath ) ); + if( strlen( $searchpath ) ) { + $wgDatabase->doQuery( "ALTER USER $wgDBuser SET search_path = $searchpath" ); + } + $goodconf = array( + 'client_min_messages' => 'error', + 'DateStyle' => 'ISO, YMD', + 'TimeZone' => 'GMT' + ); + foreach( array_keys( $goodconf ) AS $key ) { + $value = $goodconf[$key]; + if( !array_key_exists( $key, $conf ) or $conf[$key] !== $value ) { + print "Setting $key to '$value' for user \"$wgDBuser\"\n"; + $wgDatabase->doQuery( "ALTER USER $wgDBuser SET $key = '$value'" ); + } + } + $newsequences = array( "log_log_id_seq", "pr_id_val", @@ -1228,7 +1263,6 @@ function do_postgres_updates() { $newrules = array( ); - foreach ($newsequences as $ns) { if ($wgDatabase->sequenceExists($ns)) { echo "... sequence $ns already exists\n"; -- 2.20.1