From 15177c0891709741452cac2828f6a77d0548c7bd Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Tue, 28 May 2019 14:14:02 +0000 Subject: [PATCH] Bug 22996: Move barcode separators to a preference This patch makes batchMod.pl and inventory.pl pick the barcode separators from a new pref BarcodeSeparators (instead of hardcoding these separators differently). A few other code locations may be potential candidates for such a change too. Test plan: Test inventory with a few variations of BarcodeSeparators. Test Batch item modification similarly. Signed-off-by: Marcel de Rooy Signed-off-by: Kyle M Hall Signed-off-by: Kyle M Hall --- tools/batchMod.pl | 12 ++++++++---- tools/inventory.pl | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/tools/batchMod.pl b/tools/batchMod.pl index 9b1f958950..2e6473784c 100755 --- a/tools/batchMod.pl +++ b/tools/batchMod.pl @@ -244,16 +244,18 @@ if ($op eq "show"){ my $filecontent = $input->param('filecontent'); my ( @notfoundbarcodes, @notfounditemnumbers); - my @contentlist; + my $split_chars = C4::Context->preference('BarcodeSeparators'); if ($filefh){ binmode $filefh, ':encoding(UTF-8)'; + my @contentlist; while (my $content=<$filefh>){ $content =~ s/[\r\n]*$//; push @contentlist, $content if $content; } - @contentlist = uniq @contentlist; if ($filecontent eq 'barcode_file') { + @contentlist = grep /\S/, ( map { split /[$split_chars]/ } @contentlist ); + @contentlist = uniq @contentlist; my $existing_items = Koha::Items->search({ barcode => \@contentlist }); @itemnumbers = $existing_items->get_column('itemnumber'); my %exists = map {lc($_)=>1} $existing_items->get_column('barcode'); @@ -264,6 +266,7 @@ if ($op eq "show"){ @notfoundbarcodes = grep { !$exists{$_} } @contentlist; } elsif ( $filecontent eq 'itemid_file') { + @contentlist = uniq @contentlist; @itemnumbers = Koha::Items->search({ itemnumber => \@contentlist })->get_column('itemnumber'); my %exists = map {$_=>1} @itemnumbers; @notfounditemnumbers = grep { !$exists{$_} } @contentlist; @@ -275,8 +278,9 @@ if ($op eq "show"){ push @itemnumbers, $itm->{itemnumber}; } } - if ( my $list=$input->param('barcodelist')){ - push my @barcodelist, uniq( split(/\s\n/, $list) ); + 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 }); @itemnumbers = $existing_items->get_column('itemnumber'); diff --git a/tools/inventory.pl b/tools/inventory.pl index 934f121f90..19d7090ffd 100755 --- a/tools/inventory.pl +++ b/tools/inventory.pl @@ -166,7 +166,8 @@ if ( $uploadbarcodes && length($uploadbarcodes) > 0 ) { my $lines_read=0; binmode($uploadbarcodes, ":encoding(UTF-8)"); while (my $barcode=<$uploadbarcodes>) { - push @uploadedbarcodes, grep { /\S/ } split( /[\n\r,;|-]/, $barcode ); + my $split_chars = C4::Context->preference('BarcodeSeparators'); + push @uploadedbarcodes, grep { /\S/ } split( /[$split_chars]/, $barcode ); } for my $barcode (@uploadedbarcodes) { next unless $barcode; -- 2.20.1 (Apple Git-117)