Bug 21291: (follow-up) Pass subscriptionsnumber to all tools in staff detail's sidebar
[koha_ffzg] / tools / batchMod.pl
index 94062f7..d3c8d50 100755 (executable)
@@ -207,7 +207,7 @@ if ($op eq "action") {
                 if ( $modified ) {
                     eval {
                         if ( my $item = ModItemFromMarc( $localmarcitem, $itemdata->{biblionumber}, $itemnumber ) ) {
-                            LostItem($itemnumber) if $item->{itemlost} and not $itemdata->{itemlost};
+                            LostItem($itemnumber, 'batchmod') if $item->{itemlost} and not $itemdata->{itemlost};
                         }
                     };
                 }
@@ -233,10 +233,11 @@ 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){
+        binmode $filefh, ':encoding(UTF-8)';
         while (my $content=<$filefh>){
             $content =~ s/[\r\n]*$//;
             push @contentlist, $content if $content;
@@ -244,18 +245,15 @@ if ($op eq "show"){
 
         @contentlist = uniq @contentlist;
         if ($filecontent eq 'barcode_file') {
-            foreach my $barcode (@contentlist) {
-
-                my $itemnumber = GetItemnumberFromBarcode($barcode);
-                if ($itemnumber) {
-                    push @itemnumbers,$itemnumber;
-                } else {
-                    push @notfoundbarcodes, $barcode;
-                }
-            }
+            my $existing_items = Koha::Items->search({ itemnumber => \@contentlist });
+            @itemnumbers = $existing_items->get_column('itemnumber');
+            my %exists = map {$_=>1} @{$existing_items->get_column('barcode')};
+            @notfoundbarcodes = grep { !$exists{$_} } @contentlist;
         }
         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){
@@ -267,16 +265,11 @@ if ($op eq "show"){
         if ( my $list=$input->param('barcodelist')){
             push my @barcodelist, uniq( split(/\s\n/, $list) );
 
-            foreach my $barcode (@barcodelist) {
-
-                my $itemnumber = GetItemnumberFromBarcode($barcode);
-                if ($itemnumber) {
-                    push @itemnumbers,$itemnumber;
-                } else {
-                    push @notfoundbarcodes, $barcode;
-                }
-            }
-
+            my $existing_items = Koha::Items->search({ barcode => \@barcodelist });
+            @itemnumbers = $existing_items->get_column('itemnumber');
+            my @barcodes = $existing_items->get_column('barcode');
+            my %exists = map {$_=>1} @barcodes;
+            @notfoundbarcodes = grep { !$exists{$_} } @barcodelist;
         }
     }
 
@@ -316,7 +309,7 @@ my $pref_itemcallnumber = C4::Context->preference('itemcallnumber');
 my $subfieldsToAllowForBatchmod = C4::Context->preference('SubfieldsToAllowForRestrictedBatchmod');
 my $allowAllSubfields = (
     not defined $subfieldsToAllowForBatchmod
-      or $subfieldsToAllowForBatchmod == q||
+      or $subfieldsToAllowForBatchmod eq q||
 ) ? 1 : 0;
 my @subfieldsToAllow = split(/ /, $subfieldsToAllowForBatchmod);
 
@@ -496,11 +489,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"