Bug 31161: 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: [3999900000001]
OpacHiddenItemsHidesRecord: Hide

Adminsitration->OAI set configuration->New set
Choose anything for setSpec and setName
On new set: Actrion->define mappings
Field: 952
Subfield: p
Operator: is equal to
Value: 3999900000001

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

Signed-off-by: Jake Deery <jake.deery@ptfs-europe.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
David Cook 2024-08-14 00:41:46 +00:00 committed by Katrin Fischer
parent 541199edf8
commit 95932d5ddc
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
3 changed files with 28 additions and 5 deletions

View File

@ -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)

View File

@ -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,
) );
}
}

View File

@ -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(