[Koha-cvs] koha/z3950 processz3950queue [rel_2_2]

paul poulain paul at koha-fr.org
Mon Sep 25 16:02:42 CEST 2006


CVSROOT:	/cvsroot/koha
Module name:	koha
Branch:		rel_2_2
Changes by:	paul poulain <tipaul>	06/09/25 14:02:42

Modified files:
	z3950          : processz3950queue 

Log message:
	fix for encoding issues. Usefull only for libraries with UNIMARC & latin1 framework.
	
	Note that this hack is necessary because of ZOOM behaviour that is different to Net::Z3950.
	It must NOT be reported to rel_3 or dev_week, because they are full unicode.
	
	PS : yes, it's quite a dirty hack, because it don't solve the problem, it just override it...

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/z3950/processz3950queue?cvsroot=koha&only_with_tag=rel_2_2&r1=1.13.2.5&r2=1.13.2.6

Patches:
Index: processz3950queue
===================================================================
RCS file: /cvsroot/koha/koha/z3950/Attic/processz3950queue,v
retrieving revision 1.13.2.5
retrieving revision 1.13.2.6
diff -u -b -r1.13.2.5 -r1.13.2.6
--- processz3950queue	22 Sep 2006 15:51:40 -0000	1.13.2.5
+++ processz3950queue	25 Sep 2006 14:02:42 -0000	1.13.2.6
@@ -1,6 +1,6 @@
 #!/usr/bin/perl
 
-# $Id: processz3950queue,v 1.13.2.5 2006/09/22 15:51:40 tipaul Exp $
+# $Id: processz3950queue,v 1.13.2.6 2006/09/25 14:02:42 tipaul Exp $
 use MARC::Record;
 use C4::Context;
 use DBI;
@@ -285,11 +285,48 @@
 									for ($i=1; $i<=(($numresults<80) ? ($numresults) : (80)); $i++) {
 										my $rec=$rs->record($i-1);
  										my $marcdata = $rec->raw();
-										#my $marcrecord = MARC::Record->new_from_usmarc($marcdata);
-										#warn $marcrecord->as_formatted(); 
+                                        if (C4::Context->preference("MARCFLAVOUR") eq "UNIMARC"){
+                                          warn "marcdata :".$marcdata;
+                                          my $marcrecord = MARC::Record->new_from_usmarc($marcdata);
+                                          use Encode;
+                                          use Encode::Guess;
+                                          my $targetcharset="utf8" if (C4::Context->preference("TemplateEncoding") eq "utf-8");
+                                          $targetcharset="latin1" if (C4::Context->preference("TemplateEncoding") eq "iso-8859-1");
+                                          my $decoder = guess_encoding($marcdata, qw/utf8 latin1/);
+                                          die $decoder unless ref($decoder);
+                                          warn "decodage : ".$decoder->name;
+                                          warn "decodage cible : ".$targetcharset;
+                                          my $newRecord=MARC::Record->new();
+                                          foreach my $field ($marcrecord->fields()){
+                                            my $newField=$field->clone;
+                                            if ($field->tag()<'010'){
+                                              $newRecord->insert_grouped_field($field);
+                                            } else {
+                                              foreach my $subfield ($newField->subfields()){
+  #                                               warn ' valeur avant encodage'.$subfield->[1];
+#                                                 map {char_decode($_,"UNIMARC");Encode::from_to($_,$decoder->name,$targetcharset);$_=~tr#\r##} @$subfield;
+                                                map {char_decode($_,"UNIMARC");Encode::from_to($_,$decoder->name,$targetcharset);$_=~tr#\r##} @$subfield;
+  #                                               warn ' valeur apres encodage'.$subfield->[1];
+  #                                               warn ' valeur theorique'.Encode::from_to($_,$decoder->name,$targetcharset);
+                                                if (($newField->tag eq '100')) {
+                                                    substr($subfield->[1],26,2,"0103") if ($targetcharset eq "latin1");
+                                                    substr($subfield->[1],26,4,"5050") if ($targetcharset eq "utf8");
+                                                }
+                                                $newField->update($subfield->[0]=>$subfield->[1])
+                                              }
+                                              $newRecord->insert_grouped_field($newField);
+                                            }
+                                          }
+                                          $newRecord->encoding('UTF-8') if ($targetcharset eq 'utf8');
+                                          $newRecord->encoding('MARC-8') if ($targetcharset ne 'utf8');
+                                          warn $newRecord->as_formatted(); 
+                                          $globalencoding = $targetcharset;
+                                          $result.=$newRecord->as_usmarc;
+                                        } else {
 										$globalencoding = ref($rec);
  										$result.=$marcdata;
 									}
+									}
 									my @x=split /::/,$globalencoding;
 									my ($notmarcrecord,$alreadyindb,$alreadyinfarm,$imported) = ImportBreeding($result,-1,"Z3950-$globalname",$x[3],$random);
 									my $scantimerend=time();





More information about the Koha-cvs mailing list