From 97caccbd0fea3245e3f1c701de7ba2a4e46726d8 Mon Sep 17 00:00:00 2001 From: Jared Camins-Esakov Date: Fri, 2 Dec 2011 15:24:42 +0100 Subject: [PATCH] Bug 7311: Only run analytics code if analytics are enabled MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit With the addition of the code from Bug 5528 (easy analytic record workflows), UNIMARC 461$0 and MARC21/NORMARC 773$0 have special meanings. When you import a record that uses those subfields for different data, you will get an error in /cataloguing/additem.pl. A check should be added to be sure that EasyAnalyticalRecords is enabled before trying to handle the 461$0/773$0 as bib numbers for analytics. Thanks to Frère Sébastien Marie for spotting this issue. Signed-off-by: Frère Sébastien Marie Signed-off-by: Paul Poulain --- cataloguing/additem.pl | 44 +++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index 70ca4a9dee..a734d0fefe 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -556,27 +556,28 @@ my @fields = $temp->fields(); my @hostitemnumbers; -my $analyticfield = '773'; -if ($marcflavour eq 'MARC21' || $marcflavour eq 'NORMARC') { - $analyticfield = '773'; -} elsif ($marcflavour eq 'UNIMARC') { - $analyticfield = '461'; -} -foreach my $hostfield ($temp->field($analyticfield)){ - if ($hostfield->subfield('0')){ - my $hostrecord = GetMarcBiblio($hostfield->subfield('0'), 1); - my ($itemfield, undef) = GetMarcFromKohaField( 'items.itemnumber', GetFrameworkCode($hostfield->subfield('0')) ); - foreach my $hostitem ($hostrecord->field($itemfield)){ - if ($hostitem->subfield('9') eq $hostfield->subfield('9')){ - push (@fields, $hostitem); - push (@hostitemnumbers, $hostfield->subfield('9')); +if ( C4::Context->preference('EasyAnalyticalRecords') ) { + my $analyticfield = '773'; + if ($marcflavour eq 'MARC21' || $marcflavour eq 'NORMARC') { + $analyticfield = '773'; + } elsif ($marcflavour eq 'UNIMARC') { + $analyticfield = '461'; + } + foreach my $hostfield ($temp->field($analyticfield)){ + if ($hostfield->subfield('0')){ + my $hostrecord = GetMarcBiblio($hostfield->subfield('0'), 1); + my ($itemfield, undef) = GetMarcFromKohaField( 'items.itemnumber', GetFrameworkCode($hostfield->subfield('0')) ); + foreach my $hostitem ($hostrecord->field($itemfield)){ + if ($hostitem->subfield('9') eq $hostfield->subfield('9')){ + push (@fields, $hostitem); + push (@hostitemnumbers, $hostfield->subfield('9')); + } } } } } - foreach my $field (@fields) { next if ( $field->tag() < 10 ); @@ -607,18 +608,21 @@ foreach my $field (@fields) { } } $this_row{itemnumber} = $subfieldvalue if ($field->tag() eq $itemtagfield && $subfieldcode eq $itemtagsubfield); - foreach my $hostitemnumber (@hostitemnumbers){ + + if ( C4::Context->preference('EasyAnalyticalRecords') ) { + foreach my $hostitemnumber (@hostitemnumbers){ if ($this_row{itemnumber} eq $hostitemnumber){ $this_row{hostitemflag} = 1; $this_row{hostbiblionumber}= GetBiblionumberFromItemnumber($hostitemnumber); last; } - } + } -# my $countanalytics=GetAnalyticsCount($this_row{itemnumber}); -# if ($countanalytics > 0){ +# my $countanalytics=GetAnalyticsCount($this_row{itemnumber}); +# if ($countanalytics > 0){ # $this_row{countanalytics} = $countanalytics; -# } +# } + } } if (%this_row) { -- 2.39.5