[Koha-cvs] koha/C4 Biblio.pm [rel_3_0]

paul poulain paul at koha-fr.org
Wed Oct 11 16:26:57 CEST 2006


CVSROOT:	/sources/koha
Module name:	koha
Branch:		rel_3_0
Changes by:	paul poulain <tipaul>	06/10/11 14:26:56

Modified files:
	C4             : Biblio.pm 

Log message:
	handling of UNIMARC :
	- better management of field 100 = automatic creation of the field if needed & filling encoding to unicode.
	- better management of encoding (MARC::File::XML new_from_xml()). This fix works only on my own version of M:F:XML, i think the actual one is buggy & have reported the problem to perl4lib mailing list
	- fixing a bug on MARCgetitem, that uses biblioitems.marc and not biblioitems.marcxml

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Biblio.pm?cvsroot=koha&only_with_tag=rel_3_0&r1=1.178.2.14&r2=1.178.2.15

Patches:
Index: Biblio.pm
===================================================================
RCS file: /sources/koha/koha/C4/Biblio.pm,v
retrieving revision 1.178.2.14
retrieving revision 1.178.2.15
diff -u -b -r1.178.2.14 -r1.178.2.15
--- Biblio.pm	11 Oct 2006 07:59:36 -0000	1.178.2.14
+++ Biblio.pm	11 Oct 2006 14:26:56 -0000	1.178.2.15
@@ -645,8 +645,6 @@
 =cut
 
 
-MARC::File::XML::default_record_format("UNIMARC") if (C4::Context->preference("marcflavour") eq "UNIMARC");
-
 sub MARCgettagslib {
     my ( $dbh, $forlibrarian, $frameworkcode ) = @_;
     $frameworkcode = "" unless $frameworkcode;
@@ -763,14 +761,21 @@
     $sth->execute(  $frameworkcode,$biblionumber );
     $sth->finish;
 	my $encoding = C4::Context->preference("marcflavour");
+	# deal with UNIMARC field 100 (encoding) : create it if needed & set encoding to unicode
     if ($encoding eq "UNIMARC") {
-      unless ($record->field('100') or substr($record->subfield('100',"a"),26,2) ne 50){
-          use POSIX qw(strftime);
-          my $string=strftime("%Y%m%d",localtime(time));
+        my $string;
+        if ($record->subfield(100,"a")) {
+            $string = $record->subfield(100,"a");
+            my $f100 = $record->field(100);
+            $record->delete_field($f100);
+        } else {
+            $string = POSIX::strftime("%Y%m%d", localtime);
           $string=~s/\-//g;
           $string = sprintf("%-*s",35, $string);
+        }
           substr($string,22,6,"frey50");
-          $record->insert_fields_ordered(MARC::Field->new(100,"","","a"=>$string));
+        unless ($record->subfield(100,"a")){
+            $record->insert_grouped_fields(MARC::Field->new(100,"","","a"=>$string));
       }
     }
     $sth =$dbh->prepare("update biblioitems set marc=?,marcxml=?  where biblionumber=?"   );
@@ -812,9 +817,10 @@
 	my $sth=$dbh->prepare("select marcxml from biblioitems where biblionumber=? "  );
     $sth->execute($bibid);
     my ($marcxml)=$sth->fetchrow;
+#     warn " XML : $marcxml";
     my $record = MARC::Record->new();
-    $record = MARC::Record::new_from_xml( $marcxml,"utf8" ) if $marcxml;
-    warn "record dans Biblio.pm ".$record->as_formatted;
+    $record = MARC::Record::new_from_xml( $marcxml,"utf8",C4::Context->preference('marcflavour')) if $marcxml;
+#     warn "record dans Biblio.pm ".$record->as_formatted;
 	return $record;
 }
 ############OLD VERSION HERE###############################################
@@ -915,28 +921,23 @@
 
 sub MARCgetitem {
     # Returns MARC::Record of the item passed in parameter.
-    my ( $dbh, $bibid, $itemnumber ) = @_;
+    my ( $dbh, $biblionumber, $itemnumber ) = @_;
  my $newrecord = MARC::Record->new();
+    # retrieve the XML record
+    my $sth = $dbh->prepare("select marcxml from biblioitems where biblionumber=?"  );
+    $sth->execute($biblionumber);
+    my ($marcxml)=$sth->fetchrow;
+    my $record = MARC::Record->new();
+    $record = MARC::Record::new_from_xml( $marcxml,"utf8",C4::Context->preference('marcflavour'));
 
-  my $sth =
-      $dbh->prepare("select marc from biblioitems b, items i where b.biblionumber=i.biblionumber and i.itemnumber=?"  );
-    
-    $sth->execute($itemnumber);
- my ($marc)=$sth->fetchrow;
- my $record = MARC::File::USMARC::decode($marc);
- #search item field code
-my ($itemnumberfield,$itemnumbersubfield) = MARCfind_marc_from_kohafield($dbh,'items.itemnumber','');
-	
+    # now, find where the itemnumber is stored & extract only the item
+    my ($itemnumberfield,$itemnumbersubfield) = MARCfind_marc_from_kohafield($dbh,'items.itemnumber','');
  my @fields = $record->field($itemnumberfield);
- 
      foreach my $field (@fields) {
-#my $pos=index($field->as_string() ,$itemnumber );
-
-      if ($field->subfield($itemnumbersubfield) eq $itemnumber ){
-
+        if ($field->subfield($itemnumbersubfield) eq $itemnumber ) {
 	$newrecord->insert_fields_ordered($field);
 	}
-}
+    }
     return $newrecord;
 }
 
@@ -1474,6 +1475,9 @@
 sub MARChtml2xml {
 	my ($tags,$subfields,$values,$indicator,$ind_tag) = @_;
 	my $xml= MARC::File::XML::header('UTF-8'); 
+    if (C4::Context->preference('marcflavour') eq 'UNIMARC') {
+        MARC::File::XML->default_record_format( 'UNIMARC' );
+    }
 	#$xml =~ s/UTF-8/ISO-8859-1/;
     my $prevvalue;
     my $prevtag=-1;
@@ -3835,8 +3839,14 @@
 
 =cut
 
-# $Id: Biblio.pm,v 1.178.2.14 2006/10/11 07:59:36 tipaul Exp $
+# $Id: Biblio.pm,v 1.178.2.15 2006/10/11 14:26:56 tipaul Exp $
 # $Log: Biblio.pm,v $
+# Revision 1.178.2.15  2006/10/11 14:26:56  tipaul
+# handling of UNIMARC :
+# - better management of field 100 = automatic creation of the field if needed & filling encoding to unicode.
+# - better management of encoding (MARC::File::XML new_from_xml()). This fix works only on my own version of M:F:XML, i think the actual one is buggy & have reported the problem to perl4lib mailing list
+# - fixing a bug on MARCgetitem, that uses biblioitems.marc and not biblioitems.marcxml
+#
 # Revision 1.178.2.14  2006/10/11 07:59:36  tipaul
 # removing hardcoded ccode fiels in biblioitems
 #





More information about the Koha-cvs mailing list