From a3ff0bb5cb91761677f8b3ff08fa5f12378376af Mon Sep 17 00:00:00 2001 From: Matthias Meusburger Date: Thu, 7 Apr 2011 12:04:43 +0200 Subject: [PATCH] bug 5579 : Fixes several exports to embed items - The following export pages used to embed items when exporting, this was no longer the case, so they were fixed : Intranet : - basket/downloadcart.pl, - virtualshelves/downloadshelf.pl - catalogue/export.pl Opac : - opac/opac-downloadcart.pl - opac/opac-downloadshelf.pl - opac/opac-export.pl - Notes : - GetMarcBiblio used to embed items data, this was no longer the case, so an optional parameter was added to choose if items should be embedded or not. This way, previous work on this bug is not broken, and this is a pretty usefull feature, imho. - An optional parameter has been added to SetUTF8Flag, to be able to use NFD during normalization. This was required to make Unicode/UTF-8 export work again. Signed-off-by: Claire Hernandez Signed-off-by: Chris Cormack --- C4/Biblio.pm | 8 +++-- C4/Charset.pm | 8 +++-- C4/Record.pm | 2 +- basket/downloadcart.pl | 2 +- catalogue/export.pl | 15 +++------ opac/opac-downloadcart.pl | 2 +- opac/opac-downloadshelf.pl | 2 +- opac/opac-export.pl | 56 ++++++++++++++++----------------- virtualshelves/downloadshelf.pl | 2 +- 9 files changed, 48 insertions(+), 49 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 856a74e55e..534c97d09b 100755 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -1025,16 +1025,18 @@ sub GetMarcFromKohaField { =head2 GetMarcBiblio - my $record = GetMarcBiblio($biblionumber); + my $record = GetMarcBiblio($biblionumber, [$embeditems]); Returns MARC::Record representing bib identified by C<$biblionumber>. If no bib exists, returns undef. -The MARC record contains both biblio & item data. +C<$embeditems>. If set to true, items data are included. +The MARC record contains biblio data, and items data if $embeditems is set to true. =cut sub GetMarcBiblio { my $biblionumber = shift; + my $embeditems = shift || 0; my $dbh = C4::Context->dbh; my $sth = $dbh->prepare("SELECT marcxml FROM biblioitems WHERE biblionumber=? "); $sth->execute($biblionumber); @@ -1048,6 +1050,8 @@ sub GetMarcBiblio { if ($@) { warn " problem with :$biblionumber : $@ \n$marcxml"; } return unless $record; + C4::Biblio::EmbedItemsInMarcBiblio($record, $biblionumber) if ($embeditems); + # $record = MARC::Record::new_from_usmarc( $marc) if $marc; return $record; } else { diff --git a/C4/Charset.pm b/C4/Charset.pm index a4a06e7bb4..a4e6b716f8 100644 --- a/C4/Charset.pm +++ b/C4/Charset.pm @@ -112,7 +112,7 @@ sub IsStringUTF8ish { =head2 SetUTF8Flag - my $marc_record = SetUTF8Flag($marc_record); + my $marc_record = SetUTF8Flag($marc_record, $nfd); This function sets the PERL UTF8 flag for data. It is required when using new_from_usmarc @@ -120,6 +120,8 @@ since MARC::File::USMARC does not handle PERL UTF8 setting. When editing unicode marc records fields and subfields, you would end up in double encoding without using this function. +If $nfd is set, string normalization will use NFD instead of NFC + FIXME In my opinion, this function belongs to MARC::Record and not to this package. @@ -128,13 +130,13 @@ But since it handles charset, and MARC::Record, it finds its way in that package =cut sub SetUTF8Flag{ - my ($record)=@_; + my ($record, $nfd)=@_; return unless ($record && $record->fields()); foreach my $field ($record->fields()){ if ($field->tag()>=10){ my @subfields; foreach my $subfield ($field->subfields()){ - push @subfields,($$subfield[0],NormalizeString($$subfield[1])); + push @subfields,($$subfield[0],NormalizeString($$subfield[1],$nfd)); } my $newfield=MARC::Field->new( $field->tag(), diff --git a/C4/Record.pm b/C4/Record.pm index 990bb50b52..c5727f3c03 100644 --- a/C4/Record.pm +++ b/C4/Record.pm @@ -359,7 +359,7 @@ sub marcrecord2csv { my $output; # Getting the record - my $record = GetMarcBiblio($biblio); + my $record = GetMarcBiblio($biblio, 1); next unless $record; # Getting the framework my $frameworkcode = GetFrameworkCode($biblio); diff --git a/basket/downloadcart.pl b/basket/downloadcart.pl index 456f0a4e90..392a3e4ef8 100755 --- a/basket/downloadcart.pl +++ b/basket/downloadcart.pl @@ -65,7 +65,7 @@ if ($bib_list && $format) { foreach my $biblio (@bibs) { - my $record = GetMarcBiblio($biblio); + my $record = GetMarcBiblio($biblio, 1); if ($format eq 'iso2709') { $output .= $record->as_usmarc(); diff --git a/catalogue/export.pl b/catalogue/export.pl index f6f02d7688..9bd49dec47 100755 --- a/catalogue/export.pl +++ b/catalogue/export.pl @@ -15,14 +15,9 @@ my $op=$query->param("op"); my $format=$query->param("format"); if ($op eq "export") { my $biblionumber = $query->param("bib"); - my $dbh=C4::Context->dbh; - my $sth; - if ($biblionumber) { - $sth=$dbh->prepare("SELECT marc FROM biblioitems WHERE biblionumber =?"); - $sth->execute($biblionumber); - } - while (my ($marc) = $sth->fetchrow) { - if ($marc){ + if ($biblionumber){ + + my $marc = GetMarcBiblio($biblionumber, 1); if ($format =~ /endnote/) { $marc = marc2endnote($marc); @@ -44,12 +39,12 @@ if ($op eq "export") { $marc = $marc->as_usmarc(); } elsif ($format =~ /utf8/) { - #default + C4::Charset::SetUTF8Flag($marc, 1); + $marc = $marc->as_usmarc(); } print $query->header( -type => 'application/octet-stream', -attachment=>"bib-$biblionumber.$format"); print $marc; } - } } diff --git a/opac/opac-downloadcart.pl b/opac/opac-downloadcart.pl index 7f2bb327b7..3a4cdc1051 100755 --- a/opac/opac-downloadcart.pl +++ b/opac/opac-downloadcart.pl @@ -64,7 +64,7 @@ if ($bib_list && $format) { } else { foreach my $biblio (@bibs) { - my $record = GetMarcBiblio($biblio); + my $record = GetMarcBiblio($biblio, 1); next unless $record; if ($format eq 'iso2709') { diff --git a/opac/opac-downloadshelf.pl b/opac/opac-downloadshelf.pl index ab1fe8daef..ee9b0b1547 100755 --- a/opac/opac-downloadshelf.pl +++ b/opac/opac-downloadshelf.pl @@ -68,7 +68,7 @@ if ($shelfid && $format) { foreach my $biblio (@$items) { my $biblionumber = $biblio->{biblionumber}; - my $record = GetMarcBiblio($biblionumber); + my $record = GetMarcBiblio($biblionumber, 1); next unless $record; if ($format eq 'iso2709') { diff --git a/opac/opac-export.pl b/opac/opac-export.pl index f9d3c253d3..e8f7ededc6 100755 --- a/opac/opac-export.pl +++ b/opac/opac-export.pl @@ -35,15 +35,11 @@ my $op=$query->param("op"); my $format=$query->param("format"); if ($op eq "export") { my $biblionumber = $query->param("bib"); - my $dbh=C4::Context->dbh; - my $sth; - if ($biblionumber) { - $sth=$dbh->prepare("SELECT marc FROM biblioitems WHERE biblionumber =?"); - $sth->execute($biblionumber); - } - my $error; - while (my ($marc) = $sth->fetchrow) { - if ($marc){ + my $error; + + if ($biblionumber){ + + my $marc = GetMarcBiblio($biblionumber, 1); if ($format =~ /endnote/) { $marc = marc2endnote($marc); @@ -60,32 +56,34 @@ if ($op eq "export") { } elsif ($format =~ /bibtex/) { $marc = marc2bibtex(C4::Biblio::GetMarcBiblio($biblionumber),$biblionumber); - }elsif ($format =~ /dc/) { - ($error,$marc) = marc2dcxml($marc,1); + } + elsif ($format =~ /dc/) { + ($error,$marc) = marc2dcxml($marc,1); $format = "dublin-core.xml"; } elsif ($format =~ /marc8/) { ($error,$marc) = changeEncoding($marc,"MARC","MARC21","MARC-8"); - if (! $error){ - $marc = $marc->as_usmarc(); - } + if (! $error){ + $marc = $marc->as_usmarc(); + } } elsif ($format =~ /utf8/) { - #default + C4::Charset::SetUTF8Flag($marc,1); + $marc = $marc->as_usmarc(); } - if ($error){ - print $query->header(); - print $query->start_html(); - print "

An error occured

"; - print $error; - print $query->end_html(); - } - else { - print $query->header( - -type => 'application/octet-stream', - -attachment=>"bib-$biblionumber.$format"); - print $marc; - } + + if ($error){ + print $query->header(); + print $query->start_html(); + print "

An error occured

"; + print $error; + print $query->end_html(); + } + else { + print $query->header( + -type => 'application/octet-stream', + -attachment=>"bib-$biblionumber.$format"); + print $marc; } - } + } } diff --git a/virtualshelves/downloadshelf.pl b/virtualshelves/downloadshelf.pl index 253eec1a50..1611f1abd6 100755 --- a/virtualshelves/downloadshelf.pl +++ b/virtualshelves/downloadshelf.pl @@ -68,7 +68,7 @@ if ($shelfid && $format) { foreach my $biblio (@$items) { my $biblionumber = $biblio->{biblionumber}; - my $record = GetMarcBiblio($biblionumber); + my $record = GetMarcBiblio($biblionumber, 1); if ($format eq 'iso2709') { $output .= $record->as_usmarc(); -- 2.39.5