From 30517715769a1fd47bc5731c7337fae25245296e Mon Sep 17 00:00:00 2001 From: Shi Yao Wang Date: Wed, 14 Jan 2026 14:01:20 -0500 Subject: [PATCH] Bug 41618: Add item metadata in biblios get and list API results Test plan: 1- Make an API request to both /biblios and /biblios/{biblio_id} 2- Notice the 952 field for items is missing for both 3- Apply patch 4- Repeat step 1 and notice item metadata is there in 952 field 5- Run `prove t/db_dependent/Koha/Objects/Record/Collections.t` There should be no side effect to /deleted/biblios or /authorities API --- Koha/Objects/Record/Collections.pm | 13 +++++++++++-- Koha/REST/V1/Biblios.pm | 10 +++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Koha/Objects/Record/Collections.pm b/Koha/Objects/Record/Collections.pm index 28f2021705c..53800634888 100644 --- a/Koha/Objects/Record/Collections.pm +++ b/Koha/Objects/Record/Collections.pm @@ -56,7 +56,9 @@ Allowed formats are marcxml, mij, marc and txt. Defaults to marcxml. =cut sub print_collection { - my ( $self, $format ) = @_; + my ( $self, $format, $embed_items ) = @_; + + $embed_items //= 0; my ( $start, $glue, $end, @parts ); @@ -87,7 +89,14 @@ sub print_collection { } MARC::File::XML->default_record_format($schema) if $format eq 'marcxml'; - push @parts, $serializers{$format}->( $element->record ); + + my $record; + if ( $embed_items ) { + $record = $element->metadata_record( { embed_items => 1 } ); + } else { + $record = $element->record; + } + push @parts, $serializers{$format}->( $record ); } return ( defined $start ? $start : '' ) . join( $glue, @parts ) . ( defined $end ? $end : '' ); } diff --git a/Koha/REST/V1/Biblios.pm b/Koha/REST/V1/Biblios.pm index a4d50e38005..629f3a25be4 100644 --- a/Koha/REST/V1/Biblios.pm +++ b/Koha/REST/V1/Biblios.pm @@ -68,7 +68,7 @@ sub get { ); } else { my $metadata = $biblio->metadata; - my $record = $metadata->record; + my $record = $metadata->record( { embed_items => 1 } ); my $schema = $metadata->schema // C4::Context->preference("marcflavour"); $c->respond_to( @@ -791,24 +791,24 @@ sub list { $c->res->headers->add( 'Content-Type', 'application/marcxml+xml' ); return $c->render( status => 200, - text => $biblios->print_collection('marcxml') + text => $biblios->print_collection('marcxml', 1) ); } elsif ( $c->req->headers->accept =~ m/application\/marc-in-json(;.*)?$/ ) { $c->res->headers->add( 'Content-Type', 'application/marc-in-json' ); return $c->render( status => 200, - data => $biblios->print_collection('mij') + data => $biblios->print_collection('mij', 1) ); } elsif ( $c->req->headers->accept =~ m/application\/marc(;.*)?$/ ) { $c->res->headers->add( 'Content-Type', 'application/marc' ); return $c->render( status => 200, - text => $biblios->print_collection('marc') + text => $biblios->print_collection('marc', 1) ); } elsif ( $c->req->headers->accept =~ m/text\/plain(;.*)?$/ ) { return $c->render( status => 200, - text => $biblios->print_collection('txt') + text => $biblios->print_collection('txt', 1) ); } else { return $c->render( -- 2.43.0