From 6e417f08200bd98679e6b3ed89420e775d2d0b3b 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=UTF-8 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 --- cataloguing/additem.pl | 44 ++++++++++++++++++++++++-------------------- 1 files changed, 24 insertions(+), 20 deletions(-) diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index 4442ed3..407873b 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -545,27 +545,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 ); @@ -596,18 +597,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) { -- 1.7.2.5