From b413696915aebc59740c892323e6e6bc0f5ef8ed Mon Sep 17 00:00:00 2001 From: David Cook Date: Wed, 14 Aug 2024 00:41:46 +0000 Subject: [PATCH] Bug 31161: [Alternate patch] Mark hidden records as deleted If a bib record is hidden by OpacHiddenItems, mark it as deleted in the OAI-PMH, so that it's metadata is not consumed in a new OAI-PMH harvest, and it's marked for removal if the metadata was consumed in previous harvested. Test plan: 0. Setup vi /etc/koha/sites/kohadev/oai.conf format: marcxml: metadataPrefix: marcxml metadataNamespace: http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim schema: http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd include_items: 1 Set sysprefs: OAI-PMH: Enable OAI-PMH:ConfFile: /etc/koha/sites/kohadev/oai.conf OAI-PMH:AutoUpdateSets: Enable OAI-PMH:AutoUpdateSetsEmbedItemData: Enabled OpacHiddenItems: barcode: [999900000001] OpacHiddenItemsHidesRecord: Hide Adminsitration->OAI set configuration->New set Choose anything for setSpec and setName On new set: Actrion->define mappings Field: 942 Subfield: p Operator: is equal to Value: 999900000001 perl misc/migration_tools/build_oai_sets.pl -r -v -i 1. koha-plack --restart kohadev 2. Go to http://localhost:8080/cgi-bin/koha/oai.pl?verb=ListRecords&metadataPrefix=marcxml 3. Confirm KOHA-OAI-TEST:1 is marked as deleted and not metadata visible 4. Go to http://localhost:8080/cgi-bin/koha/oai.pl?verb=ListIdentifiers&metadataPrefix=marcxml 5. Confirm KOHA-OAI-TEST:1 is marked as deleted 6. Go to http://localhost:8080/cgi-bin/koha/oai.pl?verb=GetRecord&metadataPrefix=marcxml&identifier=KOHA-OAI-TEST:1 7. Confirm record is marked as deleted and no metadata visible 8. View Sets and confirm the record appears in the set but as deleted record 9. Change OpacHiddenItemsHidesRecord syspref to "Don't hide" and repeat above steps 10. Confirm that the record metadata is now visible and the record is not marked as deleted --- Koha/OAI/Server/GetRecord.pm | 10 ++++++---- Koha/OAI/Server/ListBase.pm | 10 +++++++++- Koha/OAI/Server/Repository.pm | 13 +++++++++++++ 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/Koha/OAI/Server/GetRecord.pm b/Koha/OAI/Server/GetRecord.pm index aabfb3eb46..d8d75928df 100644 --- a/Koha/OAI/Server/GetRecord.pm +++ b/Koha/OAI/Server/GetRecord.pm @@ -98,14 +98,16 @@ sub new { push @setSpecs, $_->{spec}; } - if ($deleted) { + #NOTE: Show a deleted record if there is no metadata + # We fetch it using this method, rather than the database directly, + # so it'll include the item data + my ( $marcxml, $marcxml_error ) = + $deleted ? undef : $repository->get_biblio_marcxml( $biblionumber, $args{metadataPrefix} ); + if ( ! $marcxml ) { $self->record( Koha::OAI::Server::DeletedRecord->new($timestamp, \@setSpecs, %args) ); } else { - # We fetch it using this method, rather than the database directly, - # so it'll include the item data - 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 0c4f3a8545..4705bca227 100644 --- a/Koha/OAI/Server/ListBase.pm +++ b/Koha/OAI/Server/ListBase.pm @@ -187,12 +187,20 @@ sub GetRecords { ); } } else { + #NOTE: Show a deleted record if there is no metadata + my $deleted_status = ($deleted) ? 'deleted' : undef; + if ( !$deleted_status ) { + my ( $marcxml, $marcxml_error ) = $repository->get_biblio_marcxml( $biblionumber, $format ); + if ( !$marcxml ) { + $deleted_status = 'deleted'; + } + } $timestamp =~ s/ /T/; $timestamp .= 'Z'; $self->identifier( HTTP::OAI::Header->new( identifier => $repository->{ koha_identifier} . ':' . $biblionumber, datestamp => $timestamp, - status => $deleted ? 'deleted' : undef, + status => $deleted_status, ) ); } } diff --git a/Koha/OAI/Server/Repository.pm b/Koha/OAI/Server/Repository.pm index 4ec02811ab..7db7f874b6 100644 --- a/Koha/OAI/Server/Repository.pm +++ b/Koha/OAI/Server/Repository.pm @@ -193,6 +193,19 @@ sub get_biblio_marcxml { $decoding_error = "INVALID_METADATA"; $record = $biblio->metadata->record_strip_nonxml( { embed_items => $with_items, opac => 1 } ); } + if ($record) { + + #FIXME: Syspref this? + my $hide_record = 1; + if ($hide_record) { + my $rules = C4::Context->yaml_preference('OpacHiddenItems') // {}; + if ( $biblio->hidden_in_opac( { rules => $rules } ) ) { + return; + } + + #TODO: Also hide record if OpacSuppression is in use + } + } if ( $record && $expanded_avs ) { my $frameworkcode = GetFrameworkCode($biblionumber) || ''; my $record_processor = Koha::RecordProcessor->new( -- 2.39.2