Bugzilla – Attachment 180605 Details for
Bug 29733
MARC21: Link 7xx linking fields to marc21_linking_section.pl value builder in sample frameworks
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29733: MARC21: Link 7xx linking fields to marc21_linking_section.pl value builder
Bug-29733-MARC21-Link-7xx-linking-fields-to-marc21.patch (text/plain), 13.74 KB, created by
Janusz Kaczmarek
on 2025-04-03 21:04:25 UTC
(
hide
)
Description:
Bug 29733: MARC21: Link 7xx linking fields to marc21_linking_section.pl value builder
Filename:
MIME Type:
Creator:
Janusz Kaczmarek
Created:
2025-04-03 21:04:25 UTC
Size:
13.74 KB
patch
obsolete
>From cdd27070ab96c1308e06e35d3d380c2c6c2f849e Mon Sep 17 00:00:00 2001 >From: Janusz Kaczmarek <januszop@gmail.com> >Date: Sun, 2 Feb 2025 15:17:35 +0100 >Subject: [PATCH] Bug 29733: MARC21: Link 7xx linking fields to > marc21_linking_section.pl value builder > >When creating an analytical record from scratch and filling the 773 >field with marc21_linking_section.pl plugin, the information put >in field 773 is very basic, incomplete, sometimes buggy ($9, $0). > >Test plan >========= >1. Configure a MARC bibliographic framework: enable essential > subfields in 773: 7, a, t, b, d, g, k, x, z, w (check the Editor > checkbox), put them in this order, and chose plugin > marc21_linking_section.pl for 773 $t. >2. Start creating a new record and go to 773 $t. Activate the plugin > to find the a record to become the host record (perform a search > for 'Linux kernel development'). Note the content of the 773 > field. >3. Apply the patch, restart plack etc. >4. Repeat p. 2.-3. See that the generated 773 field contains now much > more information, including 773 $7. > >Additionally, commented code has been removed and check/variable >initialization added to get rid of warnings in log. >--- > .../value_builder/marc21_linking_section.pl | 180 +++++++++++------- > .../value_builder/marc21_linking_section.tt | 9 + > 2 files changed, 124 insertions(+), 65 deletions(-) > >diff --git a/cataloguing/value_builder/marc21_linking_section.pl b/cataloguing/value_builder/marc21_linking_section.pl >index 4e951b03f7..2f5df4665a 100755 >--- a/cataloguing/value_builder/marc21_linking_section.pl >+++ b/cataloguing/value_builder/marc21_linking_section.pl >@@ -56,7 +56,7 @@ my $launcher = sub { > my ($params) = @_; > my $query = $params->{cgi}; > my $dbh = C4::Context->dbh; >- my $op = $query->param('op'); >+ my $op = $query->param('op') // ''; > > # -- op could be equal to > # * fillinput >@@ -87,55 +87,121 @@ my $launcher = sub { > my $biblio = Koha::Biblios->find($biblionumber); > $marcrecord = $biblio->metadata->record; > >- my $subfield_value_9 = $biblionumber; >- my $subfield_value_0 = $biblionumber; >- > #my $subfield_value_0; > #$subfield_value_0 = $marcrecord->field('001')->data > # if $marcrecord->field('001'); >- my $subfield_value_w; >- if ( $marcrecord->field('001') ) { >- $subfield_value_w = $marcrecord->field('001')->data; >- } else { >- $subfield_value_w = $biblionumber; >+ my $subfield_value_w = ''; >+ >+ my $subfield_value_7 = ''; >+ my $subfield_value_9 = ''; >+ my $subfield_value_0 = ''; >+ my $subfield_value_a = ''; >+ my $subfield_value_b = ''; >+ my $subfield_value_c = ''; >+ my $subfield_value_d = ''; >+ my $subfield_value_e = ''; >+ >+ my $subfield_value_h = ''; >+ >+ my $subfield_value_i = ''; >+ my $subfield_value_k = ''; >+ >+ my $subfield_value_p = ''; >+ >+ my $subfield_value_t = ''; >+ >+ my $subfield_value_u = ''; >+ my $subfield_value_v = ''; >+ my $subfield_value_x = ''; >+ my $subfield_value_y = ''; >+ my $subfield_value_z = ''; >+ >+ my $main_entry; >+ if ( $marcrecord->field('1..') ) { >+ $main_entry = $marcrecord->field('1..')->clone; >+ if ( $main_entry->tag eq '111' ) { >+ $main_entry->delete_subfield( code => qr/[94j]/ ); >+ } else { >+ $main_entry->delete_subfield( code => qr/[94e]/ ); >+ } > } >- >- my $subfield_value_a; >- my $subfield_value_c; >- my $subfield_value_d; >- my $subfield_value_e; >- >- my $subfield_value_h; >- >- my $subfield_value_i; >- >- my $subfield_value_p; >- >- my $subfield_value_t; >- if ( $marcrecord->field('245') ) { >- $subfield_value_t = $marcrecord->title(); >+ my $s7 = "nn" . substr( $marcrecord->leader, 6, 2 ); >+ if ($main_entry) { >+ my $c1 = 'n'; >+ if ( $main_entry->tag =~ /^1[01]/ ) { >+ $c1 = $main_entry->indicator('1') >+ if $main_entry->tag =~ /^1[01]/; >+ $c1 = $main_entry->tag eq '100' ? 1 : 2 unless $c1 =~ /\d/; >+ } >+ my $c0 = >+ ( $main_entry->tag eq '100' ) ? 'p' >+ : ( >+ $main_entry->tag eq '110' ? 'c' >+ : ( $main_entry->tag eq '111' ? 'm' : 'u' ) >+ ); >+ substr( $s7, 0, 2, $c0 . $c1 ); > } >+ $subfield_value_7 = $s7; > >- my $subfield_value_u; >- my $subfield_value_v; >- my $subfield_value_x; >- my $subfield_value_y; >- my $subfield_value_z; >+ if ($main_entry) { >+ my $a = $main_entry->as_string; >+ $a =~ s/\.$// unless $a =~ /\b[a-z]{1,2}\.$/i; >+ $subfield_value_a = $a; >+ } > >- $subfield_value_x = $marcrecord->field('022')->subfield("a") >- if ( $marcrecord->field('022') ); >- $subfield_value_z = $marcrecord->field('020')->subfield("a") >- if ( $marcrecord->field('020') ); >+ my $f245c = $marcrecord->field('245')->clone; >+ $f245c->delete_subfield( code => 'c' ); >+ my $t = $f245c->as_string; >+ $t =~ s/(\s*\/\s*|\.)$//; >+ $t = ucfirst substr( $t, $f245c->indicator('2') ); >+ $subfield_value_t = $t; >+ if ( $marcrecord->field('250') ) { >+ my $b = $marcrecord->field('250')->as_string; >+ $b =~ s/\.$//; >+ $subfield_value_b = $b; >+ } >+ if ( $marcrecord->field('260') ) { >+ my $d = $marcrecord->field('260')->as_string('abc'); >+ $d =~ s/\.$//; >+ $subfield_value_d = $d; >+ } >+ for my $f ( $marcrecord->field('8[013][01]') ) { >+ my $k = $f->as_string('abcdnjltnp'); >+ if ( $f->subfield('x') ) { >+ $k .= ', ISSN ' . $f->subfield('x'); >+ } >+ if ( $f->subfield('v') ) { >+ $k .= ' ; ' . $f->subfield('v'); >+ } >+ $subfield_value_k .= $subfield_value_k ? ". $k" : $k; >+ } >+ for my $f ( $marcrecord->field('022') ) { >+ $subfield_value_x = $f->subfield('a') if $f->subfield('a'); >+ } >+ for my $f ( $marcrecord->field('020') ) { >+ $subfield_value_z = $f->subfield('a') if $f->subfield('a'); >+ } >+ if ( $marcrecord->field('001') ) { >+ my $w = $marcrecord->field('001')->data; >+ if ( $marcrecord->field('003') ) { >+ $w = '(' . $marcrecord->field('003')->data . ')' . $w; >+ } >+ $subfield_value_w = $w; >+ } >+ $subfield_value_w ||= $biblionumber; > > # escape the 's >+ $subfield_value_7 =~ s/'/\\'/g; > $subfield_value_9 =~ s/'/\\'/g; > $subfield_value_0 =~ s/'/\\'/g; > $subfield_value_a =~ s/'/\\'/g; >+ $subfield_value_b =~ s/'/\\'/g; > $subfield_value_c =~ s/'/\\'/g; > $subfield_value_d =~ s/'/\\'/g; > $subfield_value_e =~ s/'/\\'/g; > $subfield_value_h =~ s/'/\\'/g; > $subfield_value_i =~ s/'/\\'/g; >+ $subfield_value_k =~ s/'/\\'/g; > $subfield_value_p =~ s/'/\\'/g; > $subfield_value_t =~ s/'/\\'/g; > $subfield_value_u =~ s/'/\\'/g; >@@ -148,14 +214,17 @@ my $launcher = sub { > fillinput => 1, > index => scalar $query->param('index') . "", > biblionumber => $biblionumber ? $biblionumber : "", >+ subfield_value_7 => "$subfield_value_7", > subfield_value_9 => "$subfield_value_9", > subfield_value_0 => "$subfield_value_0", > subfield_value_a => "$subfield_value_a", >+ subfield_value_b => "$subfield_value_b", > subfield_value_c => "$subfield_value_c", > subfield_value_d => "$subfield_value_d", > subfield_value_e => "$subfield_value_e", > subfield_value_h => "$subfield_value_h", > subfield_value_i => "$subfield_value_i", >+ subfield_value_k => "$subfield_value_k", > subfield_value_p => "$subfield_value_p", > subfield_value_t => "$subfield_value_t", > subfield_value_u => "$subfield_value_u", >@@ -169,7 +238,7 @@ my $launcher = sub { > } elsif ( $op eq "do_search" ) { > my $search = $query->param('search'); > my $itype = $query->param('itype'); >- my $startfrom = $query->param('startfrom'); >+ my $startfrom = $query->param('startfrom') || 0; > my $resultsperpage = $query->param('resultsperpage') || 20; > my $orderby; > my $op = 'AND'; >@@ -206,35 +275,28 @@ my $launcher = sub { > my @arrayresults; > my @field_data = ($search); > for ( my $i = 0 ; $i < $total && $i < $resultsperpage ; $i++ ) { >- my $record = C4::Search::new_record_from_zebra( 'biblioserver', $results->[$i] ); >- my $rechash = TransformMarcToKoha( { record => $record } ); >- my $pos; >+ my $record = C4::Search::new_record_from_zebra( 'biblioserver', $results->[$i] ); >+ my $rechash = TransformMarcToKoha( { record => $record } ); >+ my $pos = 0; > my $countitems = $rechash->{itembumber} ? 1 : 0; >- while ( index( $rechash->{itemnumber}, '|', $pos ) > 0 ) { >- $countitems += 1; >- $pos = index( $rechash->{itemnumber}, '|', $pos ) + 1; >+ if ( $rechash->{itembumber} ) { >+ while ( index( $rechash->{itemnumber}, '|', $pos ) > 0 ) { >+ $countitems += 1; >+ $pos = index( $rechash->{itemnumber}, '|', $pos ) + 1; >+ } > } > $rechash->{totitem} = $countitems; >- my @holdingbranches = split /\|/, $rechash->{holdingbranch}; >- my @itemcallnumbers = split /\|/, $rechash->{itemcallnumber}; >- my $CN; >+ my @holdingbranches = split /\|/, $rechash->{holdingbranch} // ''; >+ my @itemcallnumbers = split /\|/, $rechash->{itemcallnumber} // ''; >+ my $CN = ''; > for ( my $i = 0 ; $i < @holdingbranches ; $i++ ) { >- $CN .= $holdingbranches[$i] . " ( " . $itemcallnumbers[$i] . " ) |"; >+ $CN .= $holdingbranches[$i] . " ( " . ( $itemcallnumbers[$i] ? $itemcallnumbers[$i] : '' ) . " ) |"; > } > $CN =~ s/ \|$//; > $rechash->{CN} = $CN; > push @arrayresults, $rechash; > } > >- # for(my $i = 0 ; $i <= $#marclist ; $i++) >- # { >- # push @field_data, { term => "marclist", val=>$marclist[$i] }; >- # push @field_data, { term => "and_or", val=>$and_or[$i] }; >- # push @field_data, { term => "excluding", val=>$excluding[$i] }; >- # push @field_data, { term => "operator", val=>$operator[$i] }; >- # push @field_data, { term => "value", val=>$value[$i] }; >- # } >- > my @numbers = (); > > if ( $total_hits > $resultsperpage ) { >@@ -262,18 +324,6 @@ my $launcher = sub { > $to = $from + $resultsperpage; > } > >- # my $link="/cgi-bin/koha/cataloguing/value_builder/unimarc4XX.pl?op=do_search&q=$search_desc&resultsperpage=$resultsperpage&startfrom=$startfrom&search=$search"; >- # foreach my $sort (@sort_by){ >- # $link.="&sort_by=".$sort."&"; >- # } >- # $template->param( >- # pagination_bar => pagination_bar( >- # $link, >- # getnbpages($hits, $results_per_page), >- # $page, >- # 'page' >- # ), >- # ); > $template->param( > result => \@arrayresults, > index => scalar $query->param('index') . "", >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/marc21_linking_section.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/marc21_linking_section.tt >index 5826e4ca22..a599fbc35b 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/marc21_linking_section.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/value_builder/marc21_linking_section.tt >@@ -184,6 +184,9 @@ > var code = subfields[i]; > var subfield = subfields[i + 1]; > >+ if (code.value == '7') { >+ subfield.value = "[% subfield_value_7 | html %]"; >+ } > if (code.value == '9') { > subfield.value = "[% subfield_value_9 | html %]"; > } >@@ -193,6 +196,9 @@ > if (code.value == 'a') { > subfield.value = "[% subfield_value_a | html %]"; > } >+ if (code.value == 'b') { >+ subfield.value = "[% subfield_value_b | html %]"; >+ } > if (code.value == 'c') { > subfield.value = "[% subfield_value_c | html %]"; > } >@@ -208,6 +214,9 @@ > if (code.value == 'i') { > subfield.value = "[% subfield_value_i | html %]"; > } >+ if (code.value == 'k') { >+ subfield.value = "[% subfield_value_k | html %]"; >+ } > if (code.value == 'p') { > subfield.value = "[% subfield_value_p | html %]"; > } >-- >2.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 29733
:
180605
|
180607