From aab6ab7e421193c9b533d4cebc3bb7c8bd33e416 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Fri, 13 Dec 2019 09:28:28 +0000 Subject: [PATCH] Bug 23800: (QA follow-up) Fix item case, reduce code The solution for items does not work, since it compares barcodes. Instead of a grep in a map, we could do simpler. Test plan: Try barcode file, order not by itemnumber. Toggle with case. Add wrong code. Try same via barcode list text area. Try an itemnumber file, reorder again. Add wrong number. Signed-off-by: Marcel de Rooy Signed-off-by: Martin Renvoize Signed-off-by: Joy Nelson --- tools/batchMod.pl | 43 ++++++++++++------------------------------- 1 file changed, 12 insertions(+), 31 deletions(-) diff --git a/tools/batchMod.pl b/tools/batchMod.pl index 6f67d63d40..124d6f0b6a 100755 --- a/tools/batchMod.pl +++ b/tools/batchMod.pl @@ -262,28 +262,17 @@ if ($op eq "show"){ if ($filecontent eq 'barcode_file') { @contentlist = grep /\S/, ( map { split /[$split_chars]/ } @contentlist ); @contentlist = uniq @contentlist; - my @existing_items = @{ Koha::Items->search({ barcode => \@contentlist })->unblessed }; - @existing_items = map { - my $barcode = $_; - grep { $_->{barcode} eq $barcode ? $_ : () } @existing_items - } @contentlist; - @itemnumbers = map { $_->{itemnumber} } @existing_items; - my @barcodes = map { $_->{barcode} } @existing_items; - # to avoid problems with case sensitivity - my %exists = map { lc($_) => 1 } @barcodes; - @contentlist = map { lc($_) } @contentlist; - @notfoundbarcodes = grep { !$exists{$_} } @contentlist; + # Note: adding lc for case insensitivity + my %itemdata = map { lc($_->{barcode}) => $_->{itemnumber} } @{ Koha::Items->search({ barcode => \@contentlist }, { columns => [ 'itemnumber', 'barcode' ] } )->unblessed }; + my @barcodes = grep { exists $itemdata{lc $_} } @contentlist; + @itemnumbers = map { exists $itemdata{lc $_} ? $itemdata{lc $_} : () } @contentlist; + @notfoundbarcodes = grep { !exists $itemdata{lc $_} } @contentlist; } elsif ( $filecontent eq 'itemid_file') { @contentlist = uniq @contentlist; - my @existing_items = @{ Koha::Items->search({ itemnumber => \@contentlist })->unblessed }; - @existing_items = map { - my $barcode = $_; - grep { $_->{barcode} eq $barcode ? $_ : () } @existing_items - } @contentlist; - @itemnumbers = map { $_->{itemnumber} } @existing_items; - my %exists = map { $_ => 1 } @itemnumbers; - @notfounditemnumbers = grep { !$exists{$_} } @contentlist; + my %itemdata = map { $_->{itemnumber} => 1 } @{ Koha::Items->search({ itemnumber => \@contentlist }, { columns => [ 'itemnumber' ] } )->unblessed }; + @itemnumbers = grep { exists $itemdata{$_} } @contentlist; + @notfounditemnumbers = grep { !exists $itemdata{$_} } @contentlist; } } else { if (defined $biblionumber){ @@ -295,18 +284,10 @@ if ($op eq "show"){ if ( my $list = $input->param('barcodelist') ) { my @barcodelist = grep /\S/, ( split /[$split_chars]/, $list ); @barcodelist = uniq @barcodelist; - - my @existing_items = @{ Koha::Items->search({ barcode => \@barcodelist })->unblessed }; - @existing_items = map { - my $barcode = $_; - grep { $_->{barcode} eq $barcode ? $_ : () } @existing_items - } @barcodelist; - @itemnumbers = map { $_->{itemnumber} } @existing_items; - my @barcodes = map { $_->{barcode} } @existing_items; - # to avoid problems with case sensitivity - my %exists = map { lc($_) => 1 } @barcodes; - @barcodelist = map { lc($_) } @barcodelist; - @notfoundbarcodes = grep { !$exists{$_} } @barcodelist; + # Note: adding lc for case insensitivity + my %itemdata = map { lc($_->{barcode}) => $_->{itemnumber} } @{ Koha::Items->search({ barcode => \@barcodelist }, { columns => [ 'itemnumber', 'barcode' ] } )->unblessed }; + @itemnumbers = map { exists $itemdata{lc $_} ? $itemdata{lc $_} : () } @barcodelist; + @notfoundbarcodes = grep { !exists $itemdata{lc $_} } @barcodelist; } } -- 2.39.5