From 98a34a88a0a6f91cdd65a5b61559a85e01418f71 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 6 Aug 2018 15:26:49 -0300 Subject: [PATCH] Bug 21141: Handle non-existent itemnumbers in batch item modification/deletion The itemnumber list passed from a file in the batch item modification/deletion tools is not tested. Like barcodes we should make sure they refer to a valid items in the DB. Test plan: - Create a file with barcodes, itemnumbers and random lines - Use the batch item modification and deletion tools with this file You should see a table with a list of invalid barcodes and itemnumbers. Without this patch you got the following error: Can't call method "title" on an undefined value at /home/vagrant/kohaclone/tools/batchMod.pl line 580 Signed-off-by: Owen Leonard Signed-off-by: Julian Maurice Signed-off-by: Nick Clemens (cherry picked from commit e8e29d3140007b9b92d97ed2f1df7445c6eeb4f9) Signed-off-by: Martin Renvoize (cherry picked from commit 54d960cb86b91bb21cc7c92e1feef9970faaf8a1) Signed-off-by: Fridolin Somers --- .../prog/en/modules/tools/batchMod-del.tt | 60 ++++++++++++------- .../prog/en/modules/tools/batchMod-edit.tt | 54 +++++++++++------ tools/batchMod.pl | 16 ++--- 3 files changed, 86 insertions(+), 44 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-del.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-del.tt index 5ad619579c..fa4bee2b93 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-del.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-del.tt @@ -46,26 +46,46 @@ $(document).ready(function(){ [% UNLESS ( action ) %] - [% IF ( notfoundbarcodes ) %] -
- [% IF ( itemresults ) %]

Warning, the following barcodes were not found:

[% ELSE %]

Warning: no barcodes were found

[% END %] -
- - - - - - - - [% FOREACH notfoundbarcode IN notfoundbarcodes %] - - [% END %] - -
Barcode
[% notfoundbarcode.barcode |html %]
- [% UNLESS ( too_many_items ) %] - [% IF ( item_loop ) %]

The following barcodes were found:

[% END %] - [% END %] - [% END %] + [% IF ( notfoundbarcodes.size ) %] +
+ [% IF ( itemresults ) %]

Warning, the following barcodes were not found:

[% ELSE %]

Warning: no barcodes were found

[% END %] +
+ + + + + + [% FOREACH notfoundbarcode IN notfoundbarcodes %] + + [% END %] + +
Barcodes not found
[% notfoundbarcode |html %]
+ [% IF ( item_loop ) %] + [% UNLESS ( too_many_items ) %] +

The following barcodes were found:

+ [% END %] + [% END %] + [% END %] + [% IF ( notfounditemnumbers.size ) %] +
+ [% IF ( itemresults ) %]

Warning, the following itemnumbers were not found:

[% ELSE %]

Warning: no itemnumbers were found

[% END %] +
+ + + + + + [% FOREACH notfounditemnumber IN notfounditemnumbers %] + + [% END %] + +
Itemnumbers not found
[% notfounditemnumber |html %]
+ [% IF ( item_loop ) %] + [% UNLESS ( too_many_items ) %] +

The following itemnumbers were found:

+ [% END %] + [% END %] + [% END %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-edit.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-edit.tt index c25dfe4b49..db99622400 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-edit.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-edit.tt @@ -90,24 +90,44 @@ $(document).ready(function(){ [% IF ( book_on_loan ) %]
Cannot Delete: item is checked out.
[% END %] [% IF ( book_reserved ) %]
Cannot Delete: item has a waiting hold.
[% END %] - [% IF ( notfoundbarcodes ) %] -

Warning, the following barcodes were not found:

- - - - - - [% FOREACH notfoundbarcode IN notfoundbarcodes %] - + [% IF ( notfoundbarcodes.size ) %] +

Warning, the following barcodes were not found:

+
Barcodes not found
[% notfoundbarcode.barcode |html %]
+ + + + + [% FOREACH notfoundbarcode IN notfoundbarcodes %] + + [% END %] + +
Barcodes not found
[% notfoundbarcode |html %]
+ [% IF ( item_loop ) %] + [% UNLESS ( too_many_items ) %] +

The following barcodes were found:

+ [% END %] [% END %] - - - [% IF ( item_loop ) %] - [% UNLESS ( too_many_items ) %] -

The following barcodes were found:

- [% END %] - [% END %] - [% END %] + [% END %] + [% IF ( notfounditemnumbers.size ) %] +

Warning, the following itemnumbers were not found:

+ + + + + + [% FOREACH notfounditemnumber IN notfounditemnumbers %] + + [% END %] + +
Itemnumbers not found
[% notfounditemnumber |html %]
+ [% IF ( item_loop ) %] + [% UNLESS ( too_many_items ) %] +

The following itemnumbers were found:

+ [% END %] + [% END %] + [% END %] + + diff --git a/tools/batchMod.pl b/tools/batchMod.pl index 7fbfd43da2..8c3b9c8b5d 100755 --- a/tools/batchMod.pl +++ b/tools/batchMod.pl @@ -234,7 +234,7 @@ if ($op eq "action") { if ($op eq "show"){ my $filefh = $input->upload('uploadfile'); my $filecontent = $input->param('filecontent'); - my @notfoundbarcodes; + my ( @notfoundbarcodes, @notfounditemnumbers); my @contentlist; if ($filefh){ @@ -257,7 +257,9 @@ if ($op eq "show"){ } } elsif ( $filecontent eq 'itemid_file') { - @itemnumbers = @contentlist; + @itemnumbers = Koha::Items->search({ itemnumber => \@contentlist })->get_column('itemnumber'); + my %exists = map {$_=>1} @itemnumbers; + @notfounditemnumbers = grep { !$exists{$_} } @contentlist; } } else { if (defined $biblionumber){ @@ -498,11 +500,11 @@ $authorised_values_sth->finish; # what's the next op ? it's what we are not in : an add if we're editing, otherwise, and edit. - $template->param(item => \@loop_data); - if (@notfoundbarcodes) { - my @notfoundbarcodesloop = map{{barcode=>$_}}@notfoundbarcodes; - $template->param(notfoundbarcodes => \@notfoundbarcodesloop); - } + $template->param( + item => \@loop_data, + notfoundbarcodes => \@notfoundbarcodes, + notfounditemnumbers => \@notfounditemnumbers + ); $nextop="action" } # -- End action="show" -- 2.39.5