[Koha-cvs] koha C4/Breeding.pm z3950/search.pl [rel_2_2]

Ryan Higgins rch at liblime.com
Fri Mar 30 01:05:26 CEST 2007


CVSROOT:	/sources/koha
Module name:	koha
Branch:		rel_2_2
Changes by:	Ryan Higgins <rych>	07/03/29 23:05:26

Modified files:
	C4             : Breeding.pm 
	z3950          : search.pl 

Log message:
	convert incoming z3950 records to utf8 via xml round trip prior to insertion in marc_breeding.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Breeding.pm?cvsroot=koha&only_with_tag=rel_2_2&r1=1.7.2.4&r2=1.7.2.5
http://cvs.savannah.gnu.org/viewcvs/koha/z3950/search.pl?cvsroot=koha&only_with_tag=rel_2_2&r1=1.3.2.21&r2=1.3.2.22

Patches:
Index: C4/Breeding.pm
===================================================================
RCS file: /sources/koha/koha/C4/Breeding.pm,v
retrieving revision 1.7.2.4
retrieving revision 1.7.2.5
diff -u -b -r1.7.2.4 -r1.7.2.5
--- C4/Breeding.pm	29 Jan 2007 23:41:36 -0000	1.7.2.4
+++ C4/Breeding.pm	29 Mar 2007 23:05:25 -0000	1.7.2.5
@@ -60,8 +60,7 @@
 	my $dbh = C4::Context->dbh;
 	my $searchisbn = $dbh->prepare("select biblioitemnumber from biblioitems where isbn=?");
 	my $searchissn = $dbh->prepare("select biblioitemnumber from biblioitems where issn=?");
-	my $searchbreeding = $dbh->prepare("select id from marc_breeding
-where isbn=? and title=?");
+	my $searchbreeding = $dbh->prepare("select id from marc_breeding  where isbn=? and title=?");
 	my $insertsql = $dbh->prepare("insert into marc_breeding (file,isbn,title,author,marc,encoding,z3950random) values(?,?,?,?,?,?,?)");
 	my $replacesql = $dbh->prepare("update marc_breeding set file=?,isbn=?,title=?,author=?,marc=?,encoding=?,z3950random=? where id=?");
 	$encoding = C4::Context->preference("marcflavour") unless $encoding;
@@ -74,15 +73,31 @@
 	for (my $i=0;$i<=$#marcarray;$i++) {
 		$breedingid=0;
 		my $marcrecord = MARC::File::USMARC::decode($marcarray[$i]."\x1D");
-		my @warnings = $marcrecord->warnings();
+#		my @warnings = $marcrecord->warnings();
+        # run through a roundtrip, check encoding, and convert to UTF-8
+        my $xmlrecord = $marcrecord->as_xml;
+        my $newmarcrecord;
+        eval {  
+                $newmarcrecord = MARC::Record::new_from_xml($xmlrecord,'UTF-8');
+            };
+        if ($@) {
+            warn "MARC Record has a problem in ImportBreeding:";
+            warn $xmlrecord;
+            warn $@;
+            next;
+        }
+        my @warnings = $newmarcrecord->warnings();
+        for my $warning (@warnings) {
+            warn "WARN".$warning;
+        }
+        $marcrecord = $newmarcrecord;
+
 		if (scalar($marcrecord->fields()) == 0) {
 			$notmarcrecord++;
             print "===================NOT MARCRECORD================";
 		} else {
             print "MARCRECORD";
 			my $oldbiblio = MARCmarc2koha($dbh,$marcrecord,'');
-#  			$oldbiblio->{title} = char_decode($oldbiblio->{title},$encoding) ;#if (C4::Context->preference("TemplateEncoding") eq "iso-8859-1");
-#  			$oldbiblio->{author} = char_decode($oldbiblio->{author},$encoding);# if (C4::Context->preference("TemplateEncoding") eq "iso-8859-1");
 			# if isbn found and biblio does not exist, add it. If isbn found and biblio exists, overwrite or ignore depending on user choice
 			# drop every "special" char : spaces, - ...
 			$oldbiblio->{isbn} =~ s/ |-|\.//g,
@@ -91,14 +106,14 @@
 			$oldbiblio->{issn} = substr($oldbiblio->{issn},0,10);
 			# search if biblio exists
 			my $biblioitemnumber;
-# 			if ($oldbiblio->{isbn}) {
-# 				$searchisbn->execute($oldbiblio->{isbn});
-# 				($biblioitemnumber) = $searchisbn->fetchrow;
-# 			} else {
-# 				$searchissn->execute($oldbiblio->{issn});
-# 				($biblioitemnumber) = $searchissn->fetchrow;
-# 			}
-			if ($biblioitemnumber) {
+ 			if ($oldbiblio->{isbn}) {
+ 				$searchisbn->execute($oldbiblio->{isbn});
+ 				($biblioitemnumber) = $searchisbn->fetchrow;
+ 			} else {
+ 				$searchissn->execute($oldbiblio->{issn});
+ 				($biblioitemnumber) = $searchissn->fetchrow;
+ 			}
+			if ($biblioitemnumber ) {  #  && ( $overwrite_biblio eq 0 )) {
 				$alreadyindb++;
 			} else {
 				# search in breeding farm

Index: z3950/search.pl
===================================================================
RCS file: /sources/koha/koha/z3950/Attic/search.pl,v
retrieving revision 1.3.2.21
retrieving revision 1.3.2.22
diff -u -b -r1.3.2.21 -r1.3.2.22
--- z3950/search.pl	26 Feb 2007 16:48:09 -0000	1.3.2.21
+++ z3950/search.pl	29 Mar 2007 23:05:26 -0000	1.3.2.22
@@ -171,19 +171,21 @@
           my $result='';
           if ($numresults>0){
 #               @breeding_loop=();
-              for ($i=0; $i<(($numresults<20) ? ($numresults) : (20)) ; $i++) {
+            for ($i=0; $i<(($numresults<5) ? ($numresults) : (5)) ; $i++) {
                   my $rec=$oResult[$k]->record($i);
                   my $marcrecord;
                   $marcdata = $rec->raw();
-                  $marcrecord= fixEncoding($marcdata);
-  ####WARNING records coming from Z3950 clients are in various character sets MARC8,UTF8,UNIMARC etc
-  ## In HEAD i change everything to UTF-8
-  # In rel2_2 i am not sure what encoding is so no character conversion is done here
-  ##Add necessary encoding changes to here -TG
+                $marcrecord = MARC::File::USMARC::decode($marcdata);
+####WARNING records coming from Z3950 clients are in various character sets MARC8,UTF8,UNIMARC etc
+## In HEAD i change everything to UTF-8
+# In rel2_2 i am not sure what encoding is so no character conversion is done here
+##Add necessary encoding changes to here -TG
                   my $oldbiblio = MARCmarc2koha($dbh,$marcrecord,"");
                   $oldbiblio->{isbn} =~ s/ |-|\.//g,
                   $oldbiblio->{issn} =~ s/ |-|\.//g,
+
                   my ($notmarcrecord,$alreadyindb,$alreadyinfarm,$imported,$breedingid)=ImportBreeding($marcdata,1,$serverhost[$k],$encoding[$k],$random);
+
                   my %row_data;
                   if ($i % 2) {
                       $toggle="#ffffcc";





More information about the Koha-cvs mailing list