From cd4f97d0b2060cbb4b262cc7dc3a040e29243f4c Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 26 Jun 2025 16:08:28 +0100 Subject: [PATCH] Bug 39545: (QA follow-up) Restore 240 field processing for subfield s This patch restores the generation of subfield s from field 240 (Uniform Title) in the MARC21 773 field generation, addressing cataloger feedback about the critical importance of this field for: - Bibles and books of the Bible - Laws and statutes - Translations - Academic and specialized library materials - Legal materials and treaties The MARC21 standard defines subfield s as "Uniform title (NR)" and this data is essential for proper bibliographic relationships. This patch also fixes a warning when 245 indicator 2 contains non-numeric values by adding proper validation. Test plan: 1. Create a record with a 240 field containing uniform title data 2. Generate a child record from it 3. Verify the 773 field now contains subfield s with the uniform title 4. Run prove t/db_dependent/Koha/Biblio.t to ensure all tests pass Sponsored-by: Open Fifth Signed-off-by: Heather Hernandez Signed-off-by: Martin Renvoize --- Koha/Biblio.pm | 11 ++++++++++- t/db_dependent/Koha/Biblio.t | 9 ++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index acaadc61892..4c88bcd8a58 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -1972,7 +1972,8 @@ sub generate_marc_host_field { my $t = $f245c->as_string; $t =~ s/[\s\/\\.]+$//; my $nonfiling = $f245c->indicator('2') // 0; - $t = ucfirst substr( $t, $nonfiling ); + $nonfiling = 0 unless $nonfiling =~ /^\d+$/; + $t = ucfirst substr( $t, $nonfiling ); push @sfd, ( 't' => $t ); } @@ -1985,6 +1986,14 @@ sub generate_marc_host_field { } } + # Subfield s - uniform title from 240 + if ( my $f240 = $marc_host->field('240') ) { + my $s = $f240->as_string('a'); + if ($s) { + push @sfd, ( 's' => $s ); + } + } + # Subfield d - publication info from 264/260 my $d; my @publication_fields = $marc_host->field('264'); diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/Biblio.t index 731278cc364..f0d32ee3009 100755 --- a/t/db_dependent/Koha/Biblio.t +++ b/t/db_dependent/Koha/Biblio.t @@ -1016,7 +1016,7 @@ subtest 'get_volumes_query' => sub { }; subtest 'generate_marc_host_field' => sub { - plan tests => 35; + plan tests => 36; $schema->storage->txn_begin; @@ -1101,6 +1101,13 @@ subtest 'generate_marc_host_field' => sub { $link = $biblio->generate_marc_host_field(); is( $link->subfield('t'), 'The capital test', "Title is capitalized after indicator offset" ); + # 240 uniform title tests + $record->append_fields( MARC::Field->new( '240', '1', '0', 'a' => 'Bible. English', 'l' => 'English' ) ); + ($biblio_id) = AddBiblio( $record, qw{} ); + $biblio = Koha::Biblios->find($biblio_id); + $link = $biblio->generate_marc_host_field(); + is( $link->subfield('s'), 'Bible. English', "Subfield s contains uniform title from 240a" ); + # 260/264 handling tests $record->append_fields( MARC::Field->new( '264', '', '', a => 'Publication 264' ), -- 2.49.0