From 57d57159d67820d50aeab32f186db5889e5cf951 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 2 Oct 2013 14:16:09 +0200 Subject: [PATCH] Bug 10985: [UNIMARC] Fix authority summary Test plan: - edit an authority summary with: NP : [200a][, 200b][ 200d][-- 152b --][ ; 200c][ (200f)] [001*] [ppn: 009*] - create a new authority with previous fields (it is possible some fields don't exist). - search this authority and verify the summary is someting like: NP : Name, D.-- NP -- 23849 ppn my_ppn: - Verify some summary for existing authority and check there are correct. /!\ For the ppn, it should be defined in the zebra indexes. --- C4/AuthoritiesMarc.pm | 52 +++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm index 9ea3b2d..5fb0351 100644 --- a/C4/AuthoritiesMarc.pm +++ b/C4/AuthoritiesMarc.pm @@ -915,34 +915,36 @@ sub BuildSummary { # feature will be enabled only for UNIMARC for backwards # compatibility. if ($summary{summary} and C4::Context->preference('marcflavour') eq 'UNIMARC') { - my @fields = $record->fields(); -# $reported_tag = '$9'.$result[$counter]; - my @stringssummary; - foreach my $field (@fields) { - my $tag = $field->tag(); - my $tagvalue = $field->as_string(); - my $localsummary= $summary{summary}; - $localsummary =~ s/\[(.?.?.?.?)$tag\*(.*?)\]/$1$tagvalue$2\[$1$tag$2\]/g; - if ($tag<10) { - if ($tag eq '001') { - $reported_tag.='$3'.$field->data(); - } - } else { - my @subf = $field->subfields; - for my $i (0..$#subf) { - my $subfieldcode = $subf[$i][0]; - my $subfieldvalue = $subf[$i][1]; - my $tagsubf = $tag.$subfieldcode; - $localsummary =~ s/\[(.?.?.?.?)$tagsubf(.*?)\]/$1$subfieldvalue$2\[$1$tagsubf$2\]/g; + my @matches = ($summary{summary} =~ m/\[(.*?)(\d{3})([\*a-z0-9])(.*?)\]/g); + my (@textbefore, @tag, @subtag, @textafter); + for(my $i = 0; $i < scalar @matches; $i++){ + push @textbefore, $matches[$i] if($i%4 == 0); + push @tag, $matches[$i] if($i%4 == 1); + push @subtag, $matches[$i] if($i%4 == 2); + push @textafter, $matches[$i] if($i%4 == 3); + } + for(my $i = scalar @tag; $i >= 0; $i--){ + my $textbefore = $textbefore[$i] || ''; + my $tag = $tag[$i] || ''; + my $subtag = $subtag[$i] || ''; + my $textafter = $textafter[$i] || ''; + my $value = ''; + my $field = $record->field($tag); + if ( $field ) { + if($subtag eq '*') { + if($tag < 10) { + $value = $textbefore . $field->data() . $textafter; + } + } else { + my @subfields = $field->subfield($subtag); + if(@subfields > 0) { + $value = $textbefore . join (" - ", @subfields) . $textafter; + } } } - push @stringssummary, $localsummary if ($localsummary ne $summary{summary}); + $summary{summary} =~ s/\[\Q$textbefore$tag$subtag$textafter\E\]/$value/; } - my $resultstring; - $resultstring = join(" -- ",@stringssummary); - $resultstring =~ s/\[(.*?)\]//g; - $resultstring =~ s/\n/
/g; - $summary{summary} = $resultstring; + $summary{summary} =~ s/\\n/
/g; } my @authorized; my @notes; -- 1.7.10.4