[Patches] [PATCH] Bug 7365: Allow 'pgsql' as synonym for 'Pg' etc. in the database scheme.

koha-patchbot at kohaaloha.com koha-patchbot at kohaaloha.com
Wed Dec 21 03:12:29 NZDT 2011


From: Marc Balmer <marc at msys.ch>
Date: Sun, 18 Dec 2011 10:30:51 +0100
Subject: [PATCH] Bug 7365:  Allow 'pgsql' as synonym for 'Pg' etc. in the database scheme.
 While here, remove some trailing whitespace (which my editor did when
 saving the file).

---
 C4/Context.pm |   47 ++++++++++++++++++++++++-----------------------
 C4/Koha.pm    |   20 ++++++++++----------
 2 files changed, 34 insertions(+), 33 deletions(-)

diff --git a/C4/Context.pm b/C4/Context.pm
index 7581faa..04248c2 100644
--- a/C4/Context.pm
+++ b/C4/Context.pm
@@ -32,7 +32,7 @@ BEGIN {
 			    eval {C4::Context->dbh();};
 			    if ($@){
 				$debug_level = 1;
-			    } 
+			    }
 			    else {
 				$debug_level =  C4::Context->preference("DebugLevel");
 			    }
@@ -50,7 +50,7 @@ BEGIN {
 		# a little example table with various version info";
 					print "
 						<h1>Koha error</h1>
-						<p>The following fatal error has occurred:</p> 
+						<p>The following fatal error has occurred:</p>
                         <pre><code>$msg</code></pre>
 						<table>
 						<tr><th>Apache</th><td>  $versions{apacheVersion}</td></tr>
@@ -64,11 +64,11 @@ BEGIN {
 				} elsif ($debug_level eq "1"){
 					print "
 						<h1>Koha error</h1>
-						<p>The following fatal error has occurred:</p> 
+						<p>The following fatal error has occurred:</p>
                         <pre><code>$msg</code></pre>";
 				} else {
 					print "<p>production mode - trapped fatal error</p>";
-				}       
+				}
                 print "</body></html>";
 			}
 		#CGI::Carp::set_message(\&handle_errors);
@@ -161,7 +161,7 @@ environment variable to the pathname of a configuration file to use.
 # 1. Path supplied via use C4::Context '/path/to/koha-conf.xml'
 # 2. Path supplied in KOHA_CONF environment variable.
 # 3. Path supplied in INSTALLED_CONFIG_FNAME, as long
-#    as value has changed from its default of 
+#    as value has changed from its default of
 #    '__KOHA_CONF_DIR__/koha-conf.xml', as happens
 #    when Koha is installed in 'standard' or 'single'
 #    mode.
@@ -171,14 +171,14 @@ environment variable to the pathname of a configuration file to use.
 
 use constant CONFIG_FNAME => "/etc/koha/koha-conf.xml";
                 # Default config file, if none is specified
-                
+
 my $INSTALLED_CONFIG_FNAME = '__KOHA_CONF_DIR__/koha-conf.xml';
                 # path to config file set by installer
                 # __KOHA_CONF_DIR__ is set by rewrite-confg.PL
                 # when Koha is installed in 'standard' or 'single'
-                # mode.  If Koha was installed in 'dev' mode, 
+                # mode.  If Koha was installed in 'dev' mode,
                 # __KOHA_CONF_DIR__ is *not* rewritten; instead
-                # developers should set the KOHA_CONF environment variable 
+                # developers should set the KOHA_CONF environment variable
 
 $context = undef;        # Initially, no context is set
 @context_stack = ();        # Initially, no saved contexts
@@ -198,13 +198,13 @@ sub KOHAVERSION {
     if(-d $cgidir . "/cgi-bin"){
         my $cgidir .= "/cgi-bin";
     }
-    
+
     do $cgidir."/kohaversion.pl" || die "NO $cgidir/kohaversion.pl";
     return kohaversion();
 }
 =head2 read_config_file
 
-Reads the specified Koha config file. 
+Reads the specified Koha config file.
 
 Returns an object containing the configuration variables. The object's
 structure is a bit complex to the uninitiated ... take a look at the
@@ -234,15 +234,15 @@ sub read_config_file {		# Pass argument naming config file to read
 
 # db_scheme2dbi
 # Translates the full text name of a database into de appropiate dbi name
-# 
+#
 sub db_scheme2dbi {
     my $name = shift;
     # for instance, we support only mysql, so don't care checking
     return "mysql";
     for ($name) {
-# FIXME - Should have other databases. 
+# FIXME - Should have other databases.
         if (/mysql/) { return("mysql"); }
-        if (/Postgres|Pg|PostgresSQL/) { return("Pg"); }
+        if (/Postgres|Pg|PostgresSQL|pgsql/) { return("Pg"); }
         if (/oracle/) { return("Oracle"); }
     }
     return undef;         # Just in case
@@ -253,7 +253,7 @@ sub import {
     # the first time the module is called
     # (a config file can be optionaly passed)
 
-    # default context allready exists? 
+    # default context allready exists?
     return if $context;
 
     # no ? so load it!
@@ -289,7 +289,7 @@ sub new {
     my $self = {};
 
     # check that the specified config file exists and is not empty
-    undef $conf_fname unless 
+    undef $conf_fname unless
         (defined $conf_fname && -s $conf_fname);
     # Figure out a good config file to load if none was specified.
     if (!defined($conf_fname))
@@ -312,7 +312,7 @@ sub new {
         # Load the desired config file.
     $self = read_config_file($conf_fname);
     $self->{"config_file"} = $conf_fname;
-    
+
     warn "read_config_file($conf_fname) returned undef" if !defined($self->{"config"});
     return undef if !defined($self->{"config"});
 
@@ -557,10 +557,10 @@ sub AUTOLOAD
   $Zconn = C4::Context->Zconn
 
 Returns a connection to the Zebra database for the current
-context. If no connection has yet been made, this method 
+context. If no connection has yet been made, this method
 creates one and connects.
 
-C<$self> 
+C<$self>
 
 C<$server> one of the servers defined in the koha-conf.xml file
 
@@ -621,7 +621,7 @@ sub _new_Zconn {
     my $servername = $context->{"config"}->{$server};
     my $user = $context->{"serverinfo"}->{$server}->{"user"};
     my $password = $context->{"serverinfo"}->{$server}->{"password"};
- $auth = 1 if($user && $password);   
+ $auth = 1 if($user && $password);
     retry:
     eval {
         # set options
@@ -676,7 +676,7 @@ sub _new_dbh
 {
 
     ## $context
-    ## correct name for db_schme        
+    ## correct name for db_scheme
     my $db_driver;
     if ($context->config("db_scheme")){
         $db_driver=db_scheme2dbi($context->config("db_scheme"));
@@ -693,7 +693,7 @@ sub _new_dbh
     my $dbh= DBI->connect("DBI:$db_driver:dbname=$db_name;host=$db_host;port=$db_port",
     $db_user, $db_passwd, {'RaiseError' => $ENV{DEBUG}?1:0 }) or die $DBI::errstr;
 	my $tz = $ENV{TZ};
-    if ( $db_driver eq 'mysql' ) { 
+    if ( $db_driver eq 'mysql' ) {
         # Koha 3.0 is utf-8, so force utf8 communication between mySQL and koha, whatever the mysql default config.
         # this is better than modifying my.cnf (and forcing all communications to be in utf8)
         $dbh->{'mysql_enable_utf8'}=1; #enable
@@ -702,7 +702,7 @@ sub _new_dbh
     }
     elsif ( $db_driver eq 'Pg' ) {
 	    $dbh->do( "set client_encoding = 'UTF8';" );
-        ($tz) and $dbh->do(qq(SET TIME ZONE = "$tz"));
+	    ($tz) and $dbh->do(qq(SET TIME ZONE = "$tz"));
     }
     return $dbh;
 }
@@ -932,7 +932,7 @@ sub userenv {
 
 =head2 set_userenv
 
-  C4::Context->set_userenv($usernum, $userid, $usercnum, $userfirstname, 
+  C4::Context->set_userenv($usernum, $userid, $usercnum, $userfirstname,
                   $usersurname, $userbranch, $userflags, $emailaddress);
 
 Establish a hash of user environment variables.
@@ -1040,6 +1040,7 @@ sub get_versions {
     {
         no warnings qw(exec); # suppress warnings if unable to find a program in $PATH
         $versions{mysqlVersion}  = `mysql -V`;
+        $versions{psqlVersion}   = `psql -V`;
         $versions{apacheVersion} = `httpd -v`;
         $versions{apacheVersion} = `httpd2 -v`            unless  $versions{apacheVersion} ;
         $versions{apacheVersion} = `apache2 -v`           unless  $versions{apacheVersion} ;
diff --git a/C4/Koha.pm b/C4/Koha.pm
index 789f674..e87a8d5 100644
--- a/C4/Koha.pm
+++ b/C4/Koha.pm
@@ -129,10 +129,10 @@ Returns a string with the name of the itemtype.
 
 sub GetSupportName{
 	my ($codestring)=@_;
-	return if (! $codestring); 
+	return if (! $codestring);
 	my $resultstring;
 	my $advanced_search_types = C4::Context->preference("AdvancedSearchTypes");
-	if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') {  
+	if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') {
 		my $query = qq|
 			SELECT description
 			FROM   itemtypes
@@ -184,7 +184,7 @@ build a HTML select with the following code :
 
 sub GetSupportList{
 	my $advanced_search_types = C4::Context->preference("AdvancedSearchTypes");
-	if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') {  
+	if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') {
 		my $query = qq|
 			SELECT *
 			FROM   itemtypes
@@ -591,7 +591,7 @@ sub getImageSets {
         push @imagesets, { imagesetname => $imagesubdir,
                            imagesetactive => $imagesetactive,
                            images       => \@imagelist };
-        
+
     }
     return \@imagesets;
 }
@@ -1094,10 +1094,10 @@ sub GetKohaAuthorisedValues {
   my %values;
   my $dbh = C4::Context->dbh;
   my $avcode = GetAuthValCode($kohafield,$fwcode);
-  if ($avcode) {  
+  if ($avcode) {
 	my $sth = $dbh->prepare("select authorised_value, lib, lib_opac from authorised_values where category=? ");
    	$sth->execute($avcode);
-	while ( my ($val, $lib, $lib_opac) = $sth->fetchrow_array ) { 
+	while ( my ($val, $lib, $lib_opac) = $sth->fetchrow_array ) {
 		$values{$val} = ($opac && $lib_opac) ? $lib_opac : $lib;
    	}
    	return \%values;
@@ -1115,7 +1115,7 @@ $subfield can be undefined
 
 Returns hashref of Code => description
 
-Returns undef if no authorised value category is defined for the given field and subfield 
+Returns undef if no authorised value category is defined for the given field and subfield
 
 =cut
 
@@ -1125,10 +1125,10 @@ sub GetKohaAuthorisedValuesFromField {
   my %values;
   my $dbh = C4::Context->dbh;
   my $avcode = GetAuthValCodeFromField($field, $subfield, $fwcode);
-  if ($avcode) {  
+  if ($avcode) {
 	my $sth = $dbh->prepare("select authorised_value, lib, lib_opac from authorised_values where category=? ");
    	$sth->execute($avcode);
-	while ( my ($val, $lib, $lib_opac) = $sth->fetchrow_array ) { 
+	while ( my ($val, $lib, $lib_opac) = $sth->fetchrow_array ) {
 		$values{$val} = ($opac && $lib_opac) ? $lib_opac : $lib;
    	}
    	return \%values;
@@ -1317,7 +1317,7 @@ sub _normalize_match_point {
 sub _isbn_cleanup {
     my $isbn = Business::ISBN->new( $_[0] );
     if ( $isbn ) {
-        $isbn = $isbn->as_isbn10 if $isbn->type eq 'ISBN13';
+        $isbn = $isbn->as_isbn10 if $isbn->tHOW COLUMNS FROMype eq 'ISBN13';
         if (defined $isbn) {
             return $isbn->as_string([]);
         }
-- 
1.7.2.5




More information about the Patches mailing list