From 657d4e91c35833601c1f8d93566b3bb0d04bc2db Mon Sep 17 00:00:00 2001 From: Fridolyn SOMERS Date: Fri, 8 Feb 2013 15:19:55 +0100 Subject: [PATCH] Bug 9566: Only run analytics code if analytics are enabled Bug 5528 introduced analytics records based on UNIMARC 461$0 and MARC21/NORMARC 773$0 and EasyAnalyticalRecords syspref. Bug 7311 added a condition around code in additem.pl. But this should be around all code related to analytics. For libraries that does not use it or use the concerned fields for other informations, it is a gain of performance. This patch adds a test with EasyAnalyticalRecords syspref around codes related to this feature. Test plan : - Set EasyAnalyticalRecords syspref to 'display' - Select a biblio with analytical datas, for example one item comming from another biblio => Check that you see analytical item in following pages : Intranet : - Perform a search that will return the biblio in results (search.pl) - Open biblio normal view (detail.pl) - Open items page (moredetail.pl) - Open holds page (request.pl) and select a borrower Opac : - Perform a search that will return the biblio in results (opac-search.pl). By now, it will appear only if XSLT is not used (this is another problem). - Open biblio normal view (opac-detail.pl) - Click on 'Place hold' (opac-reserve.pl) and click on 'A specific copy' - Set EasyAnalyticalRecords syspref to 'display' => Check that you see analytical item in the same pages. --- C4/Items.pm | 6 ++++-- C4/Reserves.pm | 11 +++++++---- C4/Search.pm | 49 +++++++++++++++++++++++++---------------------- catalogue/detail.pl | 27 +++++++++++++++----------- catalogue/moredetail.pl | 8 +++++--- opac/opac-detail.pl | 33 +++++++++++++++---------------- opac/opac-reserve.pl | 12 +++++++----- reserve/request.pl | 13 ++++++++----- 8 files changed, 90 insertions(+), 69 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index dbd06b6..8ff7647 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -2200,8 +2200,10 @@ sub DelItemCheck { my ( $dbh, $biblionumber, $itemnumber ) = @_; my $error; - my $countanalytics=GetAnalyticsCount($itemnumber); - + my $countanalytics = 0; + if ( C4::Context->preference('EasyAnalyticalRecords') ) { + $countanalytics = GetAnalyticsCount($itemnumber); + } # check that there is no issue on this item before deletion. my $sth=$dbh->prepare("select * from issues i where i.itemnumber=?"); diff --git a/C4/Reserves.pm b/C4/Reserves.pm index a380bf0..2bb81f6 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -395,10 +395,13 @@ sub CanBookBeReserved{ my ($borrowernumber, $biblionumber) = @_; my $items = GetItemnumbersForBiblio($biblionumber); - #get items linked via host records - my @hostitems = get_hostitemnumbers_of($biblionumber); - if (@hostitems){ - push (@$items,@hostitems); + + if ( C4::Context->preference('EasyAnalyticalRecords') ) { + #get items linked via host records + my @hostitems = get_hostitemnumbers_of($biblionumber); + if (@hostitems){ + push (@$items,@hostitems); + } } foreach my $item (@$items){ diff --git a/C4/Search.pm b/C4/Search.pm index 50f7d2b..3902016 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -1582,6 +1582,7 @@ Format results in a form suitable for passing to the template sub searchResults { my ( $search_context, $searchdesc, $hits, $results_per_page, $offset, $scan, $marcresults ) = @_; my $dbh = C4::Context->dbh; + my $marcflavour = C4::Context->preference("marcflavour"); my @newresults; require C4::Items; @@ -1646,7 +1647,6 @@ sub searchResults { $times = $hits; # FIXME: if $hits is undefined, why do we want to equal it? } - my $marcflavour = C4::Context->preference("marcflavour"); # We get the biblionumber position in MARC my ($bibliotag,$bibliosubf)=GetMarcFromKohaField('biblio.biblionumber',''); @@ -1727,28 +1727,31 @@ sub searchResults { # Pull out the items fields my @fields = $marcrecord->field($itemtag); - my $marcflavor = C4::Context->preference("marcflavour"); - # adding linked items that belong to host records - my $analyticsfield = '773'; - if ($marcflavor eq 'MARC21' || $marcflavor eq 'NORMARC') { - $analyticsfield = '773'; - } elsif ($marcflavor eq 'UNIMARC') { - $analyticsfield = '461'; - } - foreach my $hostfield ( $marcrecord->field($analyticsfield)) { - my $hostbiblionumber = $hostfield->subfield("0"); - my $linkeditemnumber = $hostfield->subfield("9"); - if(!$hostbiblionumber eq undef){ - my $hostbiblio = GetMarcBiblio($hostbiblionumber, 1); - my ($itemfield, undef) = GetMarcFromKohaField( 'items.itemnumber', GetFrameworkCode($hostbiblionumber) ); - if(!$hostbiblio eq undef){ - my @hostitems = $hostbiblio->field($itemfield); - foreach my $hostitem (@hostitems){ - if ($hostitem->subfield("9") eq $linkeditemnumber){ - my $linkeditem =$hostitem; - # append linked items if they exist - if (!$linkeditem eq undef){ - push (@fields, $linkeditem);} + + if ( C4::Context->preference('EasyAnalyticalRecords') ) { + # adding linked items that belong to host records + my $analyticsfield = '773'; + if ($marcflavour eq 'MARC21' || $marcflavour eq 'NORMARC') { + $analyticsfield = '773'; + } elsif ($marcflavour eq 'UNIMARC') { + $analyticsfield = '461'; + } + foreach my $hostfield ( $marcrecord->field($analyticsfield) ) { + my $hostbiblionumber = $hostfield->subfield("0"); + my $linkeditemnumber = $hostfield->subfield("9"); + if ( $hostbiblionumber && $linkeditemnumber ) { + my $hostbiblio = GetMarcBiblio($hostbiblionumber, 1); + my ($itemfield, undef) = GetMarcFromKohaField( 'items.itemnumber', GetFrameworkCode($hostbiblionumber) ); + if ( $hostbiblio ){ + my @hostitems = $hostbiblio->field($itemfield); + foreach my $hostitem (@hostitems){ + if ( $hostitem->subfield("9") eq $linkeditemnumber ){ + my $linkeditem = $hostitem; + # append linked items if they exist + if ($linkeditem) { + push (@fields, $linkeditem); + } + } } } } diff --git a/catalogue/detail.pl b/catalogue/detail.pl index ec6f6eb..f792330 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -113,7 +113,7 @@ my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour ); my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour ); my $marcseriesarray = GetMarcSeries($record,$marcflavour); my $marcurlsarray = GetMarcUrls ($record,$marcflavour); -my $marchostsarray = GetMarcHosts($record,$marcflavour); +my $marchostsarray = C4::Context->preference('EasyAnalyticalRecords') ? GetMarcHosts($record,$marcflavour) : (); my $subtitle = GetRecordValue('subtitle', $record, $fw); # Get Branches, Itemtypes and Locations @@ -129,11 +129,14 @@ for my $itm (@all_items) { # flag indicating existence of at least one item linked via a host record my $hostrecords; -# adding items linked via host biblios -my @hostitems = GetHostItemsInfo($record); -if (@hostitems){ - $hostrecords =1; - push (@items,@hostitems); +my @hostitems; +if ( C4::Context->preference('EasyAnalyticalRecords') ) { + # adding items linked via host biblios + @hostitems = GetHostItemsInfo($record); + if (@hostitems){ + $hostrecords =1; + push (@items,@hostitems); + } } my $dat = &GetBiblioData($biblionumber); @@ -258,11 +261,13 @@ foreach my $item (@items) { $item->{hosttitle} = GetBiblioData($item->{biblionumber})->{title}; } - #count if item is used in analytical bibliorecords - my $countanalytics= GetAnalyticsCount($item->{itemnumber}); - if ($countanalytics > 0){ - $analytics_flag=1; - $item->{countanalytics} = $countanalytics; + if ( C4::Context->preference('EasyAnalyticalRecords') ) { + #count if item is used in analytical bibliorecords + my $countanalytics= GetAnalyticsCount($item->{itemnumber}); + if ($countanalytics > 0){ + $analytics_flag=1; + $item->{countanalytics} = $countanalytics; + } } if (defined($item->{'materials'}) && $item->{'materials'} =~ /\S/){ diff --git a/catalogue/moredetail.pl b/catalogue/moredetail.pl index 55e8273..5b7ab7b 100755 --- a/catalogue/moredetail.pl +++ b/catalogue/moredetail.pl @@ -103,11 +103,13 @@ for my $itm (@all_items) { my $record=GetMarcBiblio($biblionumber); my $hostrecords; -# adding items linked via host biblios -my @hostitems = GetHostItemsInfo($record); -if (@hostitems){ +if ( C4::Context->preference('EasyAnalyticalRecords') ) { + # adding items linked via host biblios + my @hostitems = GetHostItemsInfo($record); + if (@hostitems){ $hostrecords =1; push (@items,@hostitems); + } } my $subtitle = GetRecordValue('subtitle', $record, $fw); diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index 94edb35..5cff4b7 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -399,21 +399,22 @@ $template->param('OPACShowBarcode' => C4::Context->preference("OPACShowBarcode") # change back when ive fixed request.pl my @all_items = GetItemsInfo( $biblionumber ); -# adding items linked via host biblios - -my $analyticfield = '773'; -if ($marcflavour eq 'MARC21' || $marcflavour eq 'NORMARC'){ - $analyticfield = '773'; -} elsif ($marcflavour eq 'UNIMARC') { - $analyticfield = '461'; -} -foreach my $hostfield ( $record->field($analyticfield)) { - my $hostbiblionumber = $hostfield->subfield("0"); - my $linkeditemnumber = $hostfield->subfield("9"); - my @hostitemInfos = GetItemsInfo($hostbiblionumber); - foreach my $hostitemInfo (@hostitemInfos){ - if ($hostitemInfo->{itemnumber} eq $linkeditemnumber){ - push(@all_items, $hostitemInfo); +if ( C4::Context->preference('EasyAnalyticalRecords') ) { + # adding items linked via host biblios + my $analyticfield = '773'; + if ($marcflavour eq 'MARC21' || $marcflavour eq 'NORMARC'){ + $analyticfield = '773'; + } elsif ($marcflavour eq 'UNIMARC') { + $analyticfield = '461'; + } + foreach my $hostfield ( $record->field($analyticfield)) { + my $hostbiblionumber = $hostfield->subfield("0"); + my $linkeditemnumber = $hostfield->subfield("9"); + my @hostitemInfos = GetItemsInfo($hostbiblionumber); + foreach my $hostitemInfo (@hostitemInfos){ + if ($hostitemInfo->{itemnumber} eq $linkeditemnumber){ + push(@all_items, $hostitemInfo); + } } } } @@ -592,7 +593,7 @@ my $marcauthorsarray = GetMarcAuthors ($record,$marcflavour); my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour); my $marcseriesarray = GetMarcSeries ($record,$marcflavour); my $marcurlsarray = GetMarcUrls ($record,$marcflavour); -my $marchostsarray = GetMarcHosts($record,$marcflavour); +my $marchostsarray = C4::Context->preference('EasyAnalyticalRecords') ? GetMarcHosts($record,$marcflavour) : (); my $subtitle = GetRecordValue('subtitle', $record, GetFrameworkCode($biblionumber)); $template->param( diff --git a/opac/opac-reserve.pl b/opac/opac-reserve.pl index 07b4f76..dc8cb0a 100755 --- a/opac/opac-reserve.pl +++ b/opac/opac-reserve.pl @@ -135,11 +135,13 @@ foreach my $biblioNumber (@biblionumbers) { # flag indicating existence of at least one item linked via a host record my $hostitemsflag; - # adding items linked via host biblios - my @hostitemInfos = GetHostItemsInfo($marcrecord); - if (@hostitemInfos){ - $hostitemsflag =1; - push (@itemInfos,@hostitemInfos); + if ( C4::Context->preference('EasyAnalyticalRecords') ) { + # adding items linked via host biblios + my @hostitemInfos = GetHostItemsInfo($marcrecord); + if (@hostitemInfos) { + $hostitemsflag = 1; + push( @itemInfos, @hostitemInfos ); + } } $biblioData->{itemInfos} = \@itemInfos; diff --git a/reserve/request.pl b/reserve/request.pl index 506d5fa..028dd92 100755 --- a/reserve/request.pl +++ b/reserve/request.pl @@ -304,11 +304,14 @@ foreach my $biblionumber (@biblionumbers) { if (my $items = get_itemnumbers_of($biblionumber)->{$biblionumber}){ @itemnumbers = @$items; } - my @hostitems = get_hostitemnumbers_of($biblionumber); - if (@hostitems){ - $template->param('hostitemsflag' => 1); - push(@itemnumbers, @hostitems); - } + + if ( C4::Context->preference('EasyAnalyticalRecords') ) { + my @hostitems = get_hostitemnumbers_of($biblionumber); + if (@hostitems){ + $template->param('hostitemsflag' => 1); + push(@itemnumbers, @hostitems); + } + } if (!@itemnumbers) { $template->param('noitems' => 1); -- 1.7.10.4