Bug Fixing : Encoding in Z3950 searches
authorHenri-Damien LAURENT <henridamien@koha-fr.org>
Wed, 23 Jan 2008 21:04:23 +0000 (15:04 -0600)
committerJoshua Ferraro <jmf@liblime.com>
Thu, 24 Jan 2008 03:31:07 +0000 (21:31 -0600)
encoding is now defaulted to MARC8
encoding is now supported for USMARC and UNIMARC flavours.
Adding Encoding field to updatedatabase.pl

Signed-off-by: Chris Cormack <crc@liblime.com>
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
C4/Koha.pm
cataloguing/z3950_search.pl
installer/data/mysql/updatedatabase.pl

index 4239fa6..3697f4a 100644 (file)
@@ -765,6 +765,7 @@ sub displayServers {
             value => $data->{host} . ":"
               . $data->{port} . "/"
               . $data->{database},
+            encoding   => ($data->{encoding}?$data->{encoding}:"iso-5426"),
             checked    => "checked",
             icon       => $data->{icon},
             zed        => $data->{type} eq 'zed',
@@ -915,7 +916,7 @@ sub FixEncoding {
   my $marc=shift;
   my $encoding=shift;
   my $record = MARC::Record->new_from_usmarc($marc);
-  if (C4::Context->preference("marcflavour") eq "UNIMARC"){
+  if (C4::Context->preference("marcflavour") eq "UNIMARC"){
     my $targetcharset="utf8";
     if ($encoding  && $targetcharset ne $encoding){   
         my $newRecord=MARC::Record->new();
@@ -931,9 +932,11 @@ sub FixEncoding {
                     my $createdfield=0;
                     foreach my $subfield ($field->subfields()){
                     if ($createdfield){
-                        if (($newField->tag eq '100')) {
+                        if ((C4::Context->preference("marcflavour") eq "UNIMARC") && ($newField->tag eq '100')) {
                             substr($subfield->[1],26,4,"5050") if ($targetcharset eq "utf8");
-                        }
+                        } elsif (C4::Context->preference("marcflavour") eq "USMARC"){
+                            $newRecord->encoding("UTF-8");                
+                        }                
                         map {$decoder->convert($_)} @$subfield;
                         $newField->add_subfields($subfield->[0]=>$subfield->[1]);
                     } else {
@@ -956,9 +959,11 @@ sub FixEncoding {
 #                     my $utf8=eval{MARC::Charset::marc8_to_utf8($subfield->[1])};
 #                     if ($@) {warn "z3950 character conversion error $@ ";$utf8=$subfield->[1]};
                     my $utf8=char_decode5426($subfield->[1]);
-                    if (($field->tag eq '100')) {
+                    if ((C4::Context->preference("marcflavour") eq "UNIMARC") && ($field->tag eq '100')) {
                         substr($utf8,26,4,"5050");
-                    }            
+                    } elsif (C4::Context->preference("marcflavour") eq "USMARC"){
+                        $newRecord->encoding("UTF-8");                
+                    }                
                     if ($createdfield){
                         $newField->add_subfields($subfield->[0]=>$utf8);
                     } else {
@@ -974,8 +979,8 @@ sub FixEncoding {
         return $newRecord;            
      }
      return $record;  
-  }
-  return $record;
+  }
+  return $record;
 }
 
 
index 7c4e146..3346f60 100755 (executable)
@@ -147,7 +147,7 @@ else {
               || $DEBUG
               && warn( "" . $oConnection[$s]->errmsg() );
             $serverhost[$s] = $server->{host};
-            $encoding[$s]   = $server->{encoding};
+            $encoding[$s]   = ($server->{encoding}?$server->{encoding}:"iso-5426");
             $s++;
         }    ## while fetch
     }    # foreach
index 9cab61b..13eb7c3 100755 (executable)
@@ -960,6 +960,15 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     SetVersion ($DBversion);
 }
 
+$DBversion = "3.00.00.049";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+      $dbh->do("ALTER TABLE z3950servers
+  ADD `encoding` text default NULL,
+  ");
+  print "Upgrade to $DBversion done ( Added encoding field to z3950servers table )\n";
+    SetVersion ($DBversion);
+}
+
 =item DropAllForeignKeys($table)
 
   Drop all foreign keys of the table $table