Check that the user is configured correctly if using Postgres
authorGreg Sabino Mullane <greg@users.mediawiki.org>
Wed, 16 May 2007 20:21:27 +0000 (20:21 +0000)
committerGreg Sabino Mullane <greg@users.mediawiki.org>
Wed, 16 May 2007 20:21:27 +0000 (20:21 +0000)
maintenance/updaters.inc

index 4707891..e46ec69 100644 (file)
@@ -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";