diff --git a/Koha/OAI/Server/GetRecord.pm b/Koha/OAI/Server/GetRecord.pm index 5e51b2fb99..aabfb3eb46 100644 --- a/Koha/OAI/Server/GetRecord.pm +++ b/Koha/OAI/Server/GetRecord.pm @@ -105,7 +105,8 @@ sub new { } else { # We fetch it using this method, rather than the database directly, # so it'll include the item data - my $marcxml = $repository->get_biblio_marcxml($biblionumber, $args{metadataPrefix}); + my ( $marcxml, $marcxml_error ) = $repository->get_biblio_marcxml( $biblionumber, $args{metadataPrefix} ); + $args{about} = [$marcxml_error] if $marcxml_error; $self->record( Koha::OAI::Server::Record->new($repository, $marcxml, $timestamp, \@setSpecs, %args) ); diff --git a/Koha/OAI/Server/ListBase.pm b/Koha/OAI/Server/ListBase.pm index 283f1b3334..6fd2891050 100644 --- a/Koha/OAI/Server/ListBase.pm +++ b/Koha/OAI/Server/ListBase.pm @@ -157,17 +157,25 @@ sub GetRecords { push @setSpecs, $_->{spec}; } if ( $metadata ) { - my $marcxml = !$deleted ? $repository->get_biblio_marcxml($biblionumber, $format) : undef; - if ( $marcxml ) { - $self->record( Koha::OAI::Server::Record->new( - $repository, $marcxml, $timestamp, \@setSpecs, - identifier => $repository->{ koha_identifier } . ':' . $biblionumber, - metadataPrefix => $token->{metadata_prefix} - ) ); + my ( $marcxml, $marcxml_error ); + ( $marcxml, $marcxml_error ) = $repository->get_biblio_marcxml( $biblionumber, $format ) if !$deleted; + my %params; + $params{identifier} = $repository->{koha_identifier} . ':' . $biblionumber; + $params{metadataPrefix} = $token->{metadata_prefix}; + $params{about} = [$marcxml_error] if $marcxml_error; + if ($marcxml) { + $self->record( + Koha::OAI::Server::Record->new( + $repository, $marcxml, $timestamp, \@setSpecs, + %params + ) + ); } else { - $self->record( Koha::OAI::Server::DeletedRecord->new( - $timestamp, \@setSpecs, identifier => $repository->{ koha_identifier } . ':' . $biblionumber - ) ); + $self->record( + Koha::OAI::Server::DeletedRecord->new( + $timestamp, \@setSpecs, identifier => $repository->{koha_identifier} . ':' . $biblionumber + ) + ); } } else { $timestamp =~ s/ /T/; @@ -175,7 +183,7 @@ sub GetRecords { $self->identifier( HTTP::OAI::Header->new( identifier => $repository->{ koha_identifier} . ':' . $biblionumber, datestamp => $timestamp, - status => $deleted ? 'deleted' : undef + status => $deleted ? 'deleted' : undef, ) ); } } diff --git a/Koha/OAI/Server/Repository.pm b/Koha/OAI/Server/Repository.pm index 0cd0df5dcf..273497412f 100644 --- a/Koha/OAI/Server/Repository.pm +++ b/Koha/OAI/Server/Repository.pm @@ -37,9 +37,12 @@ use YAML::XS; use CGI qw/:standard -oldstyle_urls/; use C4::Context; use C4::Biblio qw( GetFrameworkCode ); +use C4::Charset qw( StripNonXmlChars ); use Koha::XSLT::Base; use Koha::Biblios; +use MARC::Record; + =head1 NAME Koha::OAI::Server::Repository - Handles OAI-PMH requests for a Koha database. @@ -178,8 +181,19 @@ sub get_biblio_marcxml { } my $biblio = Koha::Biblios->find($biblionumber); - my $record = $biblio->metadata->record({ embed_items => $with_items, opac => 1 }); - if ( $expanded_avs ) { + my $record; + + # Koha::Biblio::Metadata->record throws an exception on bad encoding, + # we don't want OAI harvests to die, so we catch and warn, and try to clean the record + eval { $record = $biblio->metadata->record( { embed_items => $with_items, opac => 1 } ); }; + my $decoding_error; + if ($@) { + my $exception = $@; + $exception->rethrow unless ( $exception->isa('Koha::Exceptions::Metadata::Invalid') ); + $decoding_error = "INVALID_METADATA"; + $record = $biblio->metadata->record_strip_nonxml( { embed_items => $with_items, opac => 1 } ); + } + if ( $record && $expanded_avs ) { my $frameworkcode = GetFrameworkCode($biblionumber) || ''; my $record_processor = Koha::RecordProcessor->new( { @@ -192,8 +206,7 @@ sub get_biblio_marcxml { ); $record_processor->process($record); } - - return $record ? $record->as_xml_record() : undef; + return ( $record ? $record->as_xml_record() : undef, $decoding_error ); } diff --git a/koha-tmpl/opac-tmpl/xslt/OAI.xslt b/koha-tmpl/opac-tmpl/xslt/OAI.xslt index d7956f31ed..e81eda8a31 100644 --- a/koha-tmpl/opac-tmpl/xslt/OAI.xslt +++ b/koha-tmpl/opac-tmpl/xslt/OAI.xslt @@ -331,6 +331,37 @@ + +
+ + #about +
+
+ About +
+
+
+
+ about +
+ +
+ + + + There was a problem decoding the metadata for this record, invalid characters were stripped. See system logs for details + + + + + + +
+
+
+
+
+
@@ -388,6 +419,31 @@ + +
+
+
+ About +
+
+
+ +
+ + + + There was a problem decoding the metadata for this record, invalid characters were stripped. See system logs for details + + + + + + +
+
+
+
+