Bug 20702: Bind results of GetHostItemsInfo to the EasyAnalyticalRecords pref
authorMarcel de Rooy <m.de.rooy@rijksmuseum.nl>
Thu, 3 May 2018 11:12:19 +0000 (13:12 +0200)
committerNick Clemens <nick@bywatersolutions.com>
Fri, 22 Jun 2018 13:37:15 +0000 (13:37 +0000)
Triggered by the finding on bug 20697.
The three calls of GetHostItemsInfo should be controlled by the pref. This
patch makes the sub return an empty list when the pref is disabled.

The patch simplifies the sub by merging the two identical foreach loops
depending on the field number in MARC21/UNIMARC.

Will add a unit test on a follow-up patch.

Test plan:
See next patch.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Mark Tompsett <mtompset@hotmail.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
C4/Items.pm

index e7279ff..bf464c3 100644 (file)
@@ -1206,44 +1206,40 @@ sub GetItemsLocationInfo {
 
 =head2 GetHostItemsInfo
 
-       $hostiteminfo = GetHostItemsInfo($hostfield);
-       Returns the iteminfo for items linked to records via a host field
+    $hostiteminfo = GetHostItemsInfo($hostfield);
+    Returns the iteminfo for items linked to records via a host field
 
 =cut
 
 sub GetHostItemsInfo {
-       my ($record) = @_;
-       my @returnitemsInfo;
-
-       if (C4::Context->preference('marcflavour') eq 'MARC21' ||
-        C4::Context->preference('marcflavour') eq 'NORMARC'){
-           foreach my $hostfield ( $record->field('773') ) {
-               my $hostbiblionumber = $hostfield->subfield("0");
-               my $linkeditemnumber = $hostfield->subfield("9");
-               my @hostitemInfos = GetItemsInfo($hostbiblionumber);
-               foreach my $hostitemInfo (@hostitemInfos){
-                       if ($hostitemInfo->{itemnumber} eq $linkeditemnumber){
-                               push (@returnitemsInfo,$hostitemInfo);
-                               last;
-                       }
-               }
-           }
-       } elsif ( C4::Context->preference('marcflavour') eq 'UNIMARC'){
-           foreach my $hostfield ( $record->field('461') ) {
-               my $hostbiblionumber = $hostfield->subfield("0");
-               my $linkeditemnumber = $hostfield->subfield("9");
-               my @hostitemInfos = GetItemsInfo($hostbiblionumber);
-               foreach my $hostitemInfo (@hostitemInfos){
-                       if ($hostitemInfo->{itemnumber} eq $linkeditemnumber){
-                               push (@returnitemsInfo,$hostitemInfo);
-                               last;
-                       }
-               }
-           }
-       }
-       return @returnitemsInfo;
-}
+    my ($record) = @_;
+    my @returnitemsInfo;
 
+    if( !C4::Context->preference('EasyAnalyticalRecords') ) {
+        return @returnitemsInfo;
+    }
+
+    my @fields;
+    if( C4::Context->preference('marcflavour') eq 'MARC21' ||
+      C4::Context->preference('marcflavour') eq 'NORMARC') {
+        @fields = $record->field('773');
+    } elsif( C4::Context->preference('marcflavour') eq 'UNIMARC') {
+        @fields = $record->field('461');
+    }
+
+    foreach my $hostfield ( @fields ) {
+        my $hostbiblionumber = $hostfield->subfield("0");
+        my $linkeditemnumber = $hostfield->subfield("9");
+        my @hostitemInfos = GetItemsInfo($hostbiblionumber);
+        foreach my $hostitemInfo (@hostitemInfos) {
+            if( $hostitemInfo->{itemnumber} eq $linkeditemnumber ) {
+                push @returnitemsInfo, $hostitemInfo;
+                last;
+            }
+        }
+    }
+    return @returnitemsInfo;
+}
 
 =head2 GetLastAcquisitions