Bug 25081: Fix creation of new item for a received issue
authorJanusz Kaczmarek <januszop@gmail.com>
Tue, 7 Apr 2020 20:23:20 +0000 (22:23 +0200)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Wed, 8 Apr 2020 10:53:20 +0000 (11:53 +0100)
The Bug 23435 introduced the idea of multiple copies added while
receiving a new issue.  Unfortunately, under some circumstances, it
causes no items being added at all.  It occurs stochastically, only
under some conditions.  But it is quite likely to happen while receiving
a supplemental issue.

The reason fot hist is that, in serials-edit.pl, line ca 292 and infra,
@num_copies is treated in the same way as @tags, while it should be
treated similarly to @bibnums.  It will be obvious after examining the
content of parameters tag, subfield, field_value, ..., number_of_copies.
In other words, for every edited issue number_of_copies is a scalar.

Nota bene:
a) beter to initialize $countdistinct with zero;
b) note that in master, now, before applying the patch,
$itemhash{$item}->{'num_copies'} is treated once as a scalar
and in the next line--as an array:

$itemhash{$item}->{'num_copies'} //= 1;

for (my $copy = 0; $copy < $itemhash{$item}->{'num_copies'}[$index];){

TEST PLAN
=========
1. Have a subscription with the option "Create an item
record when receiving this serial" active and try to receive a
supplemental issue.  Control that a new item under the biblio record
(usually) will not be created.
2. Apply the patch.
3. Repeat p. 1 -- a new item should be created.

Signed-off-by: Aleisha Amohia <aleishaamohia@hotmail.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

serials/serials-edit.pl

index fd1b7bd..88445a9 100755 (executable)
@@ -294,7 +294,7 @@ if ( $op and $op eq 'serialchangestatus' ) {
         #Rebuilding ALL the data for items into a hash
         # parting them on $itemid.
         my %itemhash;
-        my $countdistinct;
+        my $countdistinct = 0;
         my $range = scalar(@itemid);
         for ( my $i = 0 ; $i < $range ; $i++ ) {
             unless ( $itemhash{ $itemid[$i] } ) {
@@ -308,6 +308,7 @@ if ( $op and $op eq 'serialchangestatus' ) {
                     $itemhash{ $itemid[$i] }->{'serial'} = $newserial;
                 }
                 $itemhash{ $itemid[$i] }->{'bibnum'} = $bibnums[$countdistinct];
+                $itemhash{ $itemid[$i] }->{'num_copies'} = $num_copies[$countdistinct];
                 $countdistinct++;
             }
             push @{ $itemhash{ $itemid[$i] }->{'tags'} },      $tags[$i];
@@ -316,7 +317,6 @@ if ( $op and $op eq 'serialchangestatus' ) {
               $field_values[$i];
             push @{ $itemhash{ $itemid[$i] }->{'ind_tag'} },   $ind_tag[$i];
             push @{ $itemhash{ $itemid[$i] }->{'indicator'} }, $indicator[$i];
-            push @{ $itemhash{ $itemid[$i] }->{'num_copies'} }, $num_copies[$i];
         }
         foreach my $item ( keys %itemhash ) {
 
@@ -346,7 +346,7 @@ if ( $op and $op eq 'serialchangestatus' ) {
 
                 $itemhash{$item}->{'num_copies'} //= 1;
 
-                for (my $copy = 0; $copy < $itemhash{$item}->{'num_copies'}[$index];){
+                for (my $copy = 0; $copy < $itemhash{$item}->{'num_copies'};){
 
                 # New Item