Bug 16365 - GetMarcStructure() "unsafe" variant in PrepareItemrecordDisplay()
authorJacek Ablewicz <abl@biblos.pk.edu.pl>
Wed, 27 Jul 2016 09:38:00 +0000 (11:38 +0200)
committerKyle M Hall <kyle@bywatersolutions.com>
Fri, 9 Sep 2016 10:43:26 +0000 (10:43 +0000)
This sub is a good candidate for the "unsafe" treatment too, it doesn't
modify nor autovivify anything in the marc structure.

Added a warning in the code regarding the $tagslib usage by the
custom item plugins, plus a small change to prevent possible
"Use of uninitialized value" warnings in the future.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Tested with neworderempty.pl and itemrecorddisplay.pl.
Amended slightly: Made warning less dramatic.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

C4/Items.pm

index e700f6f..0e894ce 100644 (file)
@@ -2860,10 +2860,10 @@ sub PrepareItemrecordDisplay {
     $frameworkcode = &GetFrameworkCode($bibnum) if $bibnum;
     my ( $itemtagfield, $itemtagsubfield ) = &GetMarcFromKohaField( "items.itemnumber", $frameworkcode );
 
-    # it would be perhaps beneficial (?) to call GetMarcStructure with 'unsafe' parameter
-    # for performance reasons, but $tagslib may be passed to $plugin->build(), and there
-    # is no way to ensure that this structure is not getting corrupted somewhere in there
-    my $tagslib = &GetMarcStructure( 1, $frameworkcode );
+    # Note: $tagslib obtained from GetMarcStructure() in 'unsafe' mode is
+    # a shared data structure. No plugin (including custom ones) should change
+    # its contents. See also GetMarcStructure.
+    my $tagslib = &GetMarcStructure( 1, $frameworkcode, { unsafe => 1 } );
 
     # return nothing if we don't have found an existing framework.
     return q{} unless $tagslib;
@@ -2887,13 +2887,13 @@ sub PrepareItemrecordDisplay {
     $query .= qq{ ORDER BY lib};
     my $authorised_values_sth = $dbh->prepare( $query );
     foreach my $tag ( sort keys %{$tagslib} ) {
-        my $previous_tag = '';
         if ( $tag ne '' ) {
 
             # loop through each subfield
             my $cntsubf;
             foreach my $subfield ( sort keys %{ $tagslib->{$tag} } ) {
                 next if IsMarcStructureInternal($tagslib->{$tag}{$subfield});
+                next unless ( $tagslib->{$tag}->{$subfield}->{'tab'} );
                 next if ( $tagslib->{$tag}->{$subfield}->{'tab'} ne "10" );
                 my %subfield_data;
                 $subfield_data{tag}           = $tag;